I have an assembly (class library project in .Net 3.5) that has some references like System.Configuration and System.Web. I use it on a web application and it works fine.
Now, I need to make a reference to a Windows Forms project and I can’t understand what is happening. When I try to create an instance of my class it does not work; an exception of type TypeInitializationException is thrown.
I try to create other instances of my assembly and those work, except this specific class.
Does anybody know what is happening?
TypeInitializationException is usually thrown when a static field of the class can’t be initialized. For example:
Will cause a TypeInitializationException prior to the first usage of BadClass if the constructor for MyClass throws.
You can look at the InnerException property of the TypeInitializationException to drill down into the cause of the failure in more detail. It will usually point you to the underlying exception that caused the type initialization to fail.