Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeInitializationException thrown for Program class

My Windows Forms application was working earlier, however suddenly it stopped working. I am getting following exception:

enter image description here

With exception details as follows:

System.TypeInitializationException was unhandled
Message: An unhandled exception of type 'System.TypeInitializationException' occurred in mscorlib.dll
Additional information: The type initializer for 'NotificationTester.Program' threw an exception.

When I click OK, the VS windows then shows following:

enter image description here

The solution was working fine earlier. I don't get whats going wrong.

like image 764
Mahesha999 Avatar asked Jul 25 '14 11:07

Mahesha999


People also ask

How do I fix the initializer for threw an exception?

Click Debug--> Exceptions and check ON all the Thrown checkboxes. This will cause the debugger to stop on all first chance exceptions and will help you find the error under the Type Initializer error that you're seeing.

What is TypeInitializationException?

Typically, the TypeInitializationException exception reflects a catastrophic condition (the runtime is unable to instantiate a type) that prevents an application from continuing. Most commonly, the TypeInitializationException is thrown in response to some change in the executing environment of the application.

What is type initializer in C#?

Type Initializers are a new language construct that allow for C# (and VB using similar syntax) to shortcut creating of custom constructors or writing additional code to initialize properties.


1 Answers

So: either one of the field-initializers, or the static constructor, for Program - is failing. Find out why. Note: the InnerException has the actual exception that was raised, but basicaly: just debug the field initializers and static constructor. So look inside the Program class for either:

static SomeType someField = /* some non-trivial expression or method call */  

or:

static Program() {     // stuff } 
like image 184
Marc Gravell Avatar answered Oct 02 '22 20:10

Marc Gravell