See Also: TypeInitializationException Members
System.Object
System.Exception
System.SystemException
System.TypeInitializationException
All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.
When a static constructor fails to initialize a type, a TypeInitializationException instance is created and passed a reference to the exception thrown by the static constructor. The TypeInitializationException.InnerException property stores the exception that was thrown by the static constructor.
The following example demonstrates an error that causes a TypeInitializationException exception.
C# Example
using System; class TypeInit { // Static constructor static TypeInit () { // Throw an application-defined exception. throw new ApplicationException("Error in Class TypeInit"); } public TypeInit() {} } class TestTypeInit { static public void Main() { try { TypeInit t = new TypeInit (); } catch (TypeInitializationException e) { Console.WriteLine("Error: {0}",e); } } }The output is
Example
Error: System.TypeInitializationException: The type initializer for "TypeInit" threw an exception. ---> System.ApplicationException: Error in Class TypeInit at TypeInit..cctor() --- End of inner exception stack trace --- at TypeInit..ctor() at TestTypeInit.Main()
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0