FxCop 1.35 brings with it the ability to suppress messages in code via the use of the SuppressMessage attribute. This allows you to do the following:
In the above example, we've suppressed the Properties Should Not Return Arrays violation for the Token property so that FxCop no longer will raise it. There are clear advantages having a suppression applied directly to the offending member or type:
When first using in-code suppression, it can be confusing as to why FxCop seems to ignore these attributes. The SuppressMessage attribute is what is called a 'conditional' attribute. A conditional attribute is an attribute that is only included in metadata of your assembly if a certain compilation symbol is defined at compile time. The SuppressMessage attribute itself requires the CODE_ANALYSIS symbol to be present and by default, this is not included in non-team system projects.
To define this symbol is easy, simply do the following:
Visual C# 2005:
Visual Basic 2005:
Visual C++/CLI 2005:
Once you have recompiled your assembly, FxCop should now respect any in-code suppressions.
As always, if you have any questions or issues with FxCop or Managed Code Analysis (including the SuppressMessageAttribute) head over to the FxCop forum.