System.TypeInitializationException Class

public sealed class TypeInitializationException : SystemException

Base Types

Object
  Exception
    SystemException
      TypeInitializationException

Assembly

mscorlib

Library

BCL

Summary

Represents the error that occurs when an exception is thrown inside the static constructor of a type.

Description

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.

Example

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()
 

See Also

System Namespace

Members

TypeInitializationException Properties

TypeInitializationException.TypeName Property


TypeInitializationException.TypeName Property

public string TypeName { get; }

Summary

Gets the fully qualified name of the type that causes the exception.

Property Value

A String that contains the fully qualified name of the type that caused the exception.

Description

This property is read-only.

The System.TypeInitializationException.TypeName property returns the same value as was passed into the constructor.

See Also

System.TypeInitializationException Class, System Namespace