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.
In my case the reason was, that
<configSections>
wasn't first one inconfig
file.Move the
configSections
element to the top in your config file.Hope it helps to someone.
This issue for me was caused by a rogue user.config file that was created in the AppData\Local[Manufacturer][Product Name] directory. I'm not sure how it got there, but seems to be created every now and then.
This is one weird issue I had to deal with for the last 2 hours. I solved it by removing the static from the lists I created.
with this one:
Hope it helps and you don't have to spend two hours to find out the bug...
After trying all of the answers listed here, I have a new one:
The type initializer for 'MyLibrary' threw an exception.
If you see something like the below in the InnerException(s)..........
In my case, my directory had the correct version dll. (log4net.dll in this case).
And then ... the issue was found. Assembly redirects in the app.config.
:(
Since I had the correct version, I removed all my redirects. Your situation may be different.
Another possible reason: the app.config has duplicate sections.