This documentation is archived and is not being maintained.

SuppressMessageAttribute Class

Updated: August 2010

Suppresses reporting of a specific static analysis tool rule violation, allowing multiple suppressions on a single code artifact.

Namespace:  System.Diagnostics.CodeAnalysis
Assembly:  mscorlib (in mscorlib.dll)

[AttributeUsageAttribute(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
public sealed class SuppressMessageAttribute : Attribute

This attribute can be applied to any application element. For a complete list of the violations that can be suppressed, see Code Analysis for Managed Code Warnings.


The ConditionalAttribute is applied to this class, specifying the preprocessing symbol "CODE_ANALYSIS" as the conditional symbol that determines whether the attribute call is included or omitted. If the symbol is defined, the attribute call is included; otherwise, the call is omitted.

The following code example shows the use of the SuppressMessageAttribute attribute to suppress performance warning messages.

using System;
using System.Diagnostics.CodeAnalysis;

namespace CodeAnalysisSample
    class Library
        [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "isChecked")]
        [SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "fileIdentifier")]
        static void FileNode(string name, bool isChecked)
            string fileIdentifier = name;
            string fileName = name;
            string version = String.Empty;



Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0




August 2010

Added link to list of warning messages that can be suppressed.

Customer feedback.