My Windows Forms application was working earlier, however suddenly it stopped working. I am getting following exception:
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:
The solution was working fine earlier. I don't get whats going wrong.
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.
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.
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.
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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With