public sealed class TypeInitializationException : SystemException
Object
Exception
SystemException
TypeInitializationException
mscorlib
BCL
Represents the error that occurs when an exception is thrown inside the static constructor of a type.
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 System.TypeInitializationException.InnerException property stores the exception that was thrown by the static constructor.
The following example demonstrates an error that causes a TypeInitializationException exception.
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
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()
System Namespace
TypeInitializationException Properties
public string TypeName { get; }
Gets the fully qualified name of the type that causes the exception.
A String that contains the fully qualified name of the type that caused the exception.
This property is read-only.The System.TypeInitializationException.TypeName property returns the same value as was passed into the constructor.
System.TypeInitializationException Class, System Namespace