Export (0) Print
Expand All

Avoid uninstantiated internal classes

TypeName

AvoidUninstantiatedInternalClasses

CheckId

CA1812

Category

Microsoft.Performance

Breaking Change

NonBreaking

An instance of an assembly-level type is not created by code within the assembly. The following types are not examined by this rule:

  • Value types.

  • Abstract types.

  • Enumerations.

  • Delegates.

  • Compiler-emitted array types.

  • Uninstantiable types that define static methods only.

This rule tries to locate a call to one of the type's constructors, and reports a violation if no call is found.

To fix a violation of this rule, remove the type, or add the code that uses it. If the type contains only static methods, add one of the following to the type to prevent the compiler from emitting a default public instance constructor:

  • A private constructor (for types targeting .NET Framework versions 1.0 and 1.1).

  • The static modifier (for types targeting .NET Framework 2.0).

It is safe to exclude a warning from this rule, but there are no known scenarios where this is required.

Community Additions

ADD
Show:
© 2014 Microsoft