.net-4.0

How do I query a VARCHAR as an integer

Hello, I have a column that holds VARCHARs and I have a flag that determines if the value is a string or integer. I would like perform a search on the integers but they are stored as VARCHAR. How do I do this? I am trying to do this in a where clause. var q = from x in context.table where x.Criteria > 0 select new ...

In Silverlight, how do I handle an error during an asynchronous call?

In my SL4 app, I have a call to a service, svc.SubmitAsync(). Since this is an async call, once the method is hit, my code goes on to the next line. This is fine as long as the user enters the correct user name and password. If they don't, EndSubmit() throws an exception. EndSubmit() is in References.cs, part of the auto-generated Silver...

Quick way to get the contents of a MemoryStream as an ASCII string

I have a JSON string in a MemoryStream. I am using the following code to get it out as an ASCII string: MemoryStream memstream = new MemoryStream(); /* Write a JSON string to memstream here */ byte[] jsonBytes = new byte[memstream.Length]; memstream.Read(jsonBytes, 0, (int)memstream.Length); string jsonString = Encoding.ASCII.GetStri...

NSIS Installer with .NET 4.0

Is there a standard/preferred method for automatically downloading and installing the .NET 4.0 Framework from an NSIS installer, if the machine doesn't already have it? There are several examples for making this work on older versions of the framework, but seemingly none of them work for 4.0. Before I hack something together myself, I ...

System tray tooltip formatting

Hi, I am creating a NotifyIcon and then calling this to show a balloon-tip from the system tray: _trayIcon.ShowBalloonTip(100000, notifierTitle, notifierText, ToolTipIcon.Info); Everything works fine but I wondered: is there any way to format the text in a system tray tooltip? (In my case, notifierText) Obviously, I am adding newlin...

WPF Application still runs in background after closing

This is slightly related to the question asked here yet the answer does not apply to my case as I am not using threads: WPF Not closing properly I have converted one of my WinForm application to a WPF application, nothing drastic needed to be done except for change a few words to the WPF/C# 4.0 equivalents (MessageBoxButtons to Message...

Is this a bug in the Code Contracts rewriter?

I am experimenting with .NET Code Contracts. The following code runs just fine when runtime contract checking is turned off, but fails when runtime contract checking is turned on: using System.Collections.Generic; using System.Diagnostics.Contracts; namespace ConsoleApplication1 { public class Item<T> where T : class { } public...

PDB files with .EXE or .DLL extension

I have a .net 4.0 web project which is running in debug mode. This was running perfectly until recently. Now it errors saying it can't fine various PDB files. The PDB files it is looking for is are all present. However looking at the trace .NET is trying to find them with either a .pdb.exe or .pdb.dll extension. Why is it looking for the...

What Replaces Code Access Security in .net

With the demise of Code Access Security, how do we restrict access to a DLL in .Net framework 4.0? Specifically, we have a project with a UI layer and a business layer. The UI layer tells the business layer who the user is. What we are trying to stop is any dll other than the UI layer calling the business layer and saying "Hi I am Joe"...

Is this combination of ConcurrentDictionary and ConcurrentQueue thread-safe?

I'm using the ConcurrentDictionary and ConcurrentQueue classes from .NET 4 in the following code. Is this code thread-safe? If not, how can I make it thread-safe? public class Page { public string Name {get; set; } } public class PageQueue { private ConcurrentDictionary<int, ConcurrentQueue<Page>> pages = new Concurren...

Is there a way to throttle the threads used by Task Parallel Library?

I'm using the TPL but I'm finding it tricky unit testing code that uses it. I'm trying to not introduce a wrapper over it as I feel it could introduce issues. I understand that you can set processor affinity in the TPL, but what'd be really nice is to set a thread maximum (probably per app-domain). Therefore, when setting the thread m...

The membership provider name specified is invalid. Parameter name: providerName

.Net4.0 MVC 2 NHibernate NUnit I'm trying to test user creation. From my test, I'm calling the following: MembershipCreateStatus status; // _session is my current NHibernate session. var mmp = new MyMembershipProvider(_session); mmp.CreateUser(username, password, "[email protected]", "", "", true, Guid.NewGuid(), out status); ...

Add winlogon login method using C# and YubiKey

As for personal fun and challenge, I wanted to add a way to login on my own personal computers. All are currently using Windows 7. Normally this would use ICredentialProvider or something like that. Basically the goal here is to have 2 way to login, the normal user/password one and the alternative (mine) with a Yubikey. Is there any wh...

Saving in the WF4 WorkflowDesigner

How do I save the XAML for a WF4 workflow in a rehosted designer, without writing it to a file? I want to store the serialised workflow in a database as an XML string. Given a WorkflowDesigner instance called w, this saves to a file fine: WorkflowDesigner.Flush(); w.Save("filename.xaml"); I was hoping this would serialise to a string...

ICollectionView Sorting issue in ListView

I saw ICollectionView being introduced with WPF to handle situations when you need sorting and filtering enabled. I even saw few articles which sort items, but my main concern is why my approach is failing. Lets see my code : <ListView ItemsSource="{Binding}" x:Name="lvItems" GridViewColumnHeader.Click="ListView_Click"> <L...

Cannot open database "our database" requested by the login. The login failed. Login failed for user 'ADUser'

We are rolling out our first .net 4.0 entity framework application and are having an issue with security. We have it working on our alpha site inside our development environment with the following setup: SQL2005 IIS6 .NET 4.0 asp.net mvc 2 Entity Framework NTLM But when we moved it to our production environment for beta testing we ...

Why is GetVirtualPath failing after upgrading to .NET 4

I have the following route defined: var route = new Route("{id}/{a}/{b}", new MvcRouteHandler()); route.Defaults = new RouteValueDictionary(new { controller = "Home", action = "Show" }); route.Defaults.Add("a", ""); route.Defaults.Add("b", ""); And the following controller code: public ActionResult Show(int id) { RouteValue...

Good Learning Material on Parallel Extension of .Net 4

Can anybody please suggest me some good learning materials on the new Parallel Extensions and its use in .Net 4 except the MSDN one, so that I can learn - parallel programming on .Net 4 the basic differences between non-parallel and parallel programming paradigms how to create data-structures that supports parallel computation? Any f...

.NET WebRequest Throttling

I'm using C# .NET 4 and MSSQL. The code uses WebRequest to download the html of different websites. The code is multi threaded. I want to limit the number of requests per mintue for a pre-defined list of domains. For example Domain: www.domain1.com Request Per Min : 5 Domain: www.domain2.com Request Per Min : 20 i saw some questio...

JQuery WCF .net 4 Rest 405 Method Not Allowed Trivial

I keep getting a 405 Method not allowed. The script is hosted on same port as server, using IIS. <script> function auth() { var str= '{"Password":"Password","Username":"Username"}'; $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "http://127.0.0.1:8080/auth/authenticate", data: s...