TypeInitializationException exception on creating an object

TypeInitializationException is usually thrown when a static field of the class can’t be initialized. For example:

class BadClass
{
    private static MyClass fieldName = new MyClass();
}

Will cause a TypeInitializationException prior to the first usage of BadClass if the constructor for MyClass throws.

You can look at the InnerException property of the TypeInitializationException to drill down into the cause of the failure in more detail. It will usually point you to the underlying exception that caused the type initialization to fail.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)