Rediģēt

Kopīgot, izmantojot


Remove invalid global 'SuppressMessageAttribute' (IDE0076)

Property Value
Rule ID IDE0076
Title Remove invalid global SuppressMessageAttribute
Category CodeQuality
Subcategory Miscellaneous rules
Applicable languages C# and Visual Basic

Overview

This rule flags global SuppressMessageAttributes that have an invalid Scope or Target. The attribute should either be removed or fixed to refer to a valid scope and target symbol.

Options

This rule has no associated code-style options.

Example

// IDE0076: Invalid target '~F:N.C.F2' - no matching field named 'F2'
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Category", "Id: Title", Scope = "member", Target = "~F:N.C.F2")]
// IDE0076: Invalid scope 'property'
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Category", "Id: Title", Scope = "property", Target = "~P:N.C.P")]

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

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

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 IDE0076
// The code that's violating the rule is on this line.
#pragma warning restore IDE0076

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

[*.{cs,vb}]
dotnet_diagnostic.IDE0076.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