.NET, Archive, C#

.NET Extension Methods

Jason / December 1, 2008

Starting in .NET 3.5 is a feature called extension methods. Extension methods allow developers to extend classes with their own instance methods. This is a concept often called mix-ins in other languages. read more

Archive, Blog

Moving dasBlog to IIS7

Jason / November 17, 2008

Some of you may have noticed that several pages on this blog have been generating 404 errors for the past week or so. This was due, in part, to my recent migration to a Windows Server 2008 (IIS7) machine. Most of the blogs service interruption could have been avoided had I properly "test drove" the website after the migration. But in my haste I simply transferred the files to the remote server, hit the home page, and called it a night. Little did I know that most of the blogs content was unreachable. read more

.NET, Archive, Visual Studio

Acquiring a Public Key Before Compiling

Jason / November 17, 2008

In the past I have talked about the The Wonders Of InternalsVisibleTo and how such a simple attribute allows for internal components to be shared between different assemblies, opening the door to greater code separation and dependency control. In that previous article I illustrated how you can use the tool that ships with Visual Studio to get the public key signature from one of your existing dlls. read more

Archive, NHibernate

Migrating to NHibernate 2.0

Jason / November 8, 2008

The NHibernate documentation is often very handy when working on NHibernate based project. I keep PDF copies of the documentation to NHibernate 1.0 and 1.2 on my hard drive as I never know when I will need to reference them. Unfortunately the NHibernate team seems to have dropped the ball in regards to version 2.0. Not only does the NHibernate website lack any documentation on version 2.0, the website acts as if version 2.0 hasn’t even been released yet. Unlike previous updates to the framework, version 2.0 represents a complete refactoring of the code base with many namespaces and objects either removed or renamed. Despite the lack of official documentation there are still several resources to help you migrate your existing NHibernate 1.2 application to NHibernate 2.0.

List of breaking changes

The NHibernate forum has a thread discussing the breaking changes between version 1.2 and an alpha pre-release of 2.0. For the complete list check out the forum, however here are the ones you will be most likely to face.

Problem: The NHibernate.Expression namespace no longer exists.

Overview: Most notable of the items formerly kept in this namespace was the Expression object used when creating ICriteria. Fortunately the object still existing in the NHibernate.Criterion namespace.

Solution: Replace all “using” statements to reflect the namespace change.

//using NHibernate.Expression; //this line is no longer needed in NH 2.0
using NHibernate.Criterion;    //replace it with this line.

Problem: The nhibernate configuration section (most likely in your web.config or app.config) is no longer used.

Overview: NHibernate 2.0 no longer looks at the configuration section named nhibernate, instead it looks for a configuration section called hibernate-configuration (notice the lack of an “n” in hibernate). Moreover the configuration section wasn’t simply renamed, it bears and entirely different schema.

Solution: In short the entire configuration section is going to have to be reworked slightly.

For starters your configuration section declaration will have to change its name and type:

<configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" requirePermission="false"/> </configSections> read more

.NET, Archive, Software Design

A Generic Error Occurred in GDI+

Jason / October 14, 2008

You know you’re doing good when your application crashes with an exception as detailed as “a generic error occurred in gdi+”. That is about as, well generic, as it gets :- )

In my particular case I was constructing an Image down in my DAO using the FromStream method, like so:

Image result;
using (FileStream file = File.OpenRead(filename)) {
	result = Image.FromStream(file);
	file.Close();
}
return result;

I was doing this so that I could know for a fact that the file was being disposed of properly. I didn’t want to have any orphaned file references locking up the file in case I later needed to delete it.

The problem was that up in my UI I was attempting to call the Save method on Image to dump its contents out to the ASP.NET response stream, like so:

img.Save(HttpContext.Response.OutputStream, ImageFormat.Jpeg); read more