Blog Stats
  • Posts - 24
  • Articles - 0
  • Comments - 17
  • Trackbacks - 0


Thursday, February 23, 2012

Type initializer for [ClassName] threw an exception

I was helping a coworker with some code changes on a windows console application, when suddenly the entire program refused to load:

The type initializer for [program] threw an exception.

was thrown at the static void main() routine starting the console app.


The console application would not even load.  Looking into the stack trace of the exception, it seemed to point to configuration problems, so first thought was to look at the app.config.

Everything checked out.  No issues there.

After looking deeper under the cover, started looking at the class itself.  The class itself was defined as static, and there were a half dozen static properties of the object that were being assigned in the class, in addition to the program's static void main() that was trying to run. 

The exception was resulting from attempting to initialize the static variables in the static class, but the stack trace was pointing at the static void main() because technically the execution context is at that point in the application lifecycle. 



Copyright © jkrebsbach