Thursday 7 August 2008

Implementing IDisposable

Here's a test class which implements IDisposable and shows the methods and implementations you need to include:

class Test : IDisposable
{
private bool isDisposed = false;

~Test()
{
Dispose(false);
}

protected void Dispose(bool disposing)
{
if (disposing)
{
// Code to dispose the managed resources of the class
}
// Code to dispose the un-managed resources of the class

isDisposed = true;
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}

The type initializer for '...Configuration.ObjectBuilder.EnterpriseLibraryFactory' threw an exception

Saw this error today:

The type initializer for 'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory' threw an exception

A quick googling tells me that I needed to add a reference into my project to Microsoft.Practices.ObjectBuilder.dll

I added that in and hey presto, problem solved!