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.
A possible reason: init a static dictionary with duplicated keys.
I've got the same error with platform target set as any CPU and prefer 32-bit checked, unchecking that last one solved my problem.
I got the same error message and for my case the reason is my main program is set to build as 32 bit console app and I added a private variable logger which access a 64bit dll.
After I changed the main program to be build as 64bit, the issue is fixed.
So, If you didn't get an innerException message like me, you can set a breakpoint on some of the static variables like strings that you may have declared. Then you can debug forwards from there with F10.
So: either one of the field-initializers, or the static constructor, for
Program
- is failing. Find out why. Note: theInnerException
has the actual exception that was raised, but basicaly: just debug the field initializers and static constructor. So look inside theProgram
class for either:or:
Make sure you are not missing any dependency DLLs. In my case, a DLL I was referencing had a dependency on another DLL.
If this is what happened, look at the "Inner Exception" property and then you will see a better error message. In my case, it said "Cannot find xxx.dll"