Suppressing Messages in FxCop
Thursday, May 20th, 2010FxCop is a free static code analysis tool from Microsoft that checks .NET managed code assemblies for conformance to Microsoft’s .NET Framework Design Guidelines. It will ensure that the specified rules are used in the source code.
FxCop analyzes the compiled object code, not the original source code, and searches for more than 200 different possible coding standards violations.
Sometimes it is needed to automatically remove FxCop related “SuppressMessage” attributes when they are no longer needed.
If you’re using Visual Studio Team System, then FxCop is completely integrated and when you exclude messages it automatically applies the new SuppressMessage attributes to the appropriate location in code.
If you’re using Visual Studio Professional edition, then you have to use the external FxCop.
It turns out you have to enable your project to recognize the SuppressMessage attribute by FIRST adding a condition compilation symbol.
To include this symbol do the following:
For C# projects:
- In Solution Explorer, right-click your project and choose Properties
- In the Properties window, choose the Build tab
- In the Conditional compilation symbols text box enter CODE_ANALYSIS
The next step you have to do is to right-click the error message in FxCop UI and select “Copy As” – “SuppressMessage” (or “Module-level SupressMessage”). Then you can simply paste the attribute into your code at the appropriate location.


