C#idiomatic C#
ide0077fundamentals/code-analysis/style-rules

Code analysis

Avoid legacy format target in global 'SuppressMessageAttribute' (IDE0077)

Learn about code analysis rule IDE0077: Avoid legacy format target in global 'SuppressMessageAttribute'

IDE0077 CodeQuality / Miscellaneous rules
Applicable languages C# and Visual Basic

Overview

This rule flags global SuppressMessageAttributes that specify Target using the legacy FxCop target string format. Using the legacy format Target is known to have performance problems and should be avoided. For more information, see dotnet/roslyn issue 44362.

The recommended format for Target is the documentation ID format. For information about documentation IDs, see Documentation ID format.

Options

This rule has no associated code-style options.

Example

csharp
// IDE0077: Legacy format target 'N.C.#F'
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Category", "Id: Title", Scope = "member", Target = "N.C.#F")]

// Fixed code
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Category", "Id: Title", Scope = "member", Target = "~F:N.C.F")]

namespace N
{
    class C
    {
        public int F;
    }
}

Suppress a warning

If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

csharp
#pragma warning disable IDE0077
// The code that's violating the rule is on this line.
#pragma warning restore IDE0077

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

ini
[*.{cs,vb}]
dotnet_diagnostic.IDE0077.severity = none

To disable this entire category of rules, set the severity for the category to none in the configuration file.

ini
[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-CodeQuality.severity = none

For more information, see How to suppress code analysis warnings.

See also