다음을 통해 공유


Avoid uninstantiated internal classes

TypeName

AvoidUninstantiatedInternalClasses

CheckId

CA1812

Category

Microsoft.Performance

Breaking Change

NonBreaking

Cause

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.

Rule Description

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

How to Fix Violations

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

When to Exclude Warnings

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

Avoid uncalled private code

Review unused parameters

Remove unused locals