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

Property Value
Rule ID IDE0077
Title Avoid legacy format target in global SuppressMessageAttribute
Category CodeQuality
Subcategory 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.

Tip

Visual Studio 2019 provides a code fix to automatically change the Target of the attribute to the recommended format.

Options

This rule has no associated code-style options.

Example

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

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

[*.{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.

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

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

See also