All rules
CA1012Design Enabled by default: No

Abstract types should not have public constructors

Abstract types should not have public constructors

Microsoft docs

Description

Constructors on abstract types can be called only by derived types. Because public constructors create instances of a type, and you cannot create instances of an abstract type, an abstract type that has a public constructor is incorrectly designed.

Cause

A type is abstract and has a public constructor.

By default, this rule only looks at externally visible types, but this is configurable.

How to fix violations

To fix a violation of this rule, either make the constructor protected or don't declare the type as abstract.

Example

// Violates this rule
public abstract class Book
{
    public Book()
    {
    }
}

// Does not violate this rule
public abstract class Book
{
    protected Book()
    {
    }
}

When to suppress

Do not suppress a warning from this rule. The abstract type has a public constructor.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0