Category Archives: Core .NET

C# core development of all types (desktop, Silverlight, ASP.NET, etc.)

Rails-Style Test Database Creation in ASP.NET MVC

How can you get ASP.NET MVC to create your database on the fly for tests? Well, you can, if you use migrations for your application to build the tables, drop and recreate all the tables prior to running any tests. Continue reading

Posted in Core .NET, Web | Tagged , , | Leave a comment

Fetching Connection Strings from App.Config in a Library via ConfigurationManager

System.Configuration.ConfigurationManager doesn’t (easily) allow you to read connection strings from an App.Config file inside a library. You need to add a few extra steps to pull this off, like using KeyValueConfigurationElement. Continue reading

Posted in Core .NET, Web, Wndows Forms | Tagged , , | Leave a comment

Using NInject For Compile-Time AOP

An update to my aspect-oriented design pattern for compile-time checking: you can implement aspects as interfaces with singular implementations, and use Ninject to inject the interface implementations. Smooth, easy, and it works! Continue reading

Posted in Core .NET, Silverlight, Web, Wndows Forms, WPF | Tagged , , | Leave a comment

Creating Background Applications in C#

How can you create a .NET application that runs in the background, without a console or any forms? Just create a Windows Application type application, and make sure no windows appear. That’s it! Continue reading

Posted in Core .NET, Wndows Forms | Tagged | Leave a comment

Debugging Silverlight Apps in Firefox

Debugging Silverlight applications in Firefox without a Web project is easy; just enable the dom.ipc.plugins.enabled configuration point in Firefox, restart your browser, and you’re ready to go! Continue reading

Posted in Core .NET, Silverlight | Tagged | Leave a comment

Enums, SQL Server, and Null

Ever wonder how to deal with enumerations that might be null? Should you have a “nothing” value? What about SQL Server? As it turns out, enumerations are value types (often represented by integers), which means that they can be nullable! Continue reading

Posted in Core .NET, Silverlight, Web, Wndows Forms, WPF | Tagged , , | Leave a comment

Outputting Raw HTML in Razor

ASP.NET MVC3 automatically encodes content by default. To get around this, you need to both un-encode the content (by using HTML.Raw), and you need to disable ValidateInput on your controller action to avoid the error: A potentially dangerous Request.Form value was detected from the client. Continue reading

Posted in Core .NET, Web | Tagged , , | Leave a comment

Understanding and Solving Named Pipes Provider Error: 40

Visual Studio may generate an error message: A network-related or instance-specific error occurred while establishing a connection to SQL Server. [...] (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server). This error message is caused by the inability to connect to the SQL server. Your connection string is likely wrong (or missing); you can use Toad for SQL Server to generate the correct connection string (just make sure Named Pipes are enabled). Continue reading

Posted in Core .NET, Web | Tagged , , | 3 Comments

WPF Brushes: Solid, Gradient, Image, and More!

WPF objects take a Brush instance (an abstract class) for foreground and background colours. What is a legitimate brush, exactly? Surprisingly, it can be a solid colour, or a gradient (linear or radial); it can even be an image, or something more complicated (a compound image of sorts). The MSDN page gives the best overview of brushes, visually. Continue reading

Posted in Core .NET, WPF | Tagged , | Leave a comment

WPF Gotcha: Mouse* Event With a Backgroundless StackPanel

WPF’s StackPanel mouse events (MouseDown, MouseLeftButtonDown, and MouseRightButtonDown) don’t seem to work, even when the StackPanel is visible. That is, until you add a background of some colour and transparency. Strangely, this causes the events to fire — even though it was visible before. Continue reading

Posted in Core .NET, WPF | Tagged , | 3 Comments