Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0514

'constructor' : static constructor cannot have an explicit 'this' or 'base' constructor call

Calling this in the static constructor is not allowed because the static constructor is called automatically before creating any instance of the class. Also, static constructors are not inherited, and cannot be called directly.

For more information, see this (C# Reference) and base (C# Reference).

The following example generates CS0514:

// CS0514.cs
class A
{
    static A() : base(0) // CS0514
    {
    }

    public A(object o)
    {
    }
}

class B
{
    static B() : this(null) // CS0514
    {
    }

    public B(object o)
    {
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft