Day of the Developer

Living the life of a developer. What is development work really like?

<October 2006>
SuMoTuWeThFrSa
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

Post Categories

Article Categories

News

I'm a dad :) Welcome to a new life.

Navigation

Software Business Tips

My Sites

Subscriptions



TypeInitializationException - What, Why, and How to fix

So what is a TypeInitializationException?

"The exception that is thrown as a wrapper around the exception thrown by the class initializer"

So what is a "class initializer"?

A static constructor

But I don't have a static constructor on my class.

If you are working in ASP.NET with Pages or User Controls, yes you do.  The framework generates one for you.

So, basically, when you get this exception, it is because another exception was thrown while setting up a class instance, along with its default values.

Notice that the class IS being set up.  The class exists, and the constructor was in the process of being invoked.

Basically, it means that something went wrong during the setup, like a failure in assigning a new class instance to a member variable.  Such as in:

private MyClass m_MyClass = new MyClass();

Why does it happen?

OutOfMemoryException, NullReferenceException, MissingMethodException.  I've seen all of these.

Usually it is a symptom of there being a mismatch between two or more assemblies.

This can mean that either you have (for instance) upgraded one of a set of DLLs, but not one it is dependent on.

Or

In the case of ASP.NET, it may mean that the shadow copying of the assemblies had an issue, and the cached compiled versions have not updated correctly.

In the former case, you have to hunt down the version mismatch and correct it.

In the latter, you need to get a copy of the DLLs from the site bin folder.  Delete the site copies.  Upload the copies you made back into the site bin folder.

 

posted on Friday, October 27, 2006 10:16 PM by admin

Powered by Community Server, by Telligent Systems