Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When you are applying <a href="http://msdn.microsoft.com/en-us/library/dd264939" rel="nofollow">code analysis</a> to your project you will sometimes get warnings that you want to ignore either because the warning is a false positive or because it is OK for a specific part of your code to violate a code analysis rule.</p> <p>You do that by using the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.codeanalysis.suppressmessageattribute.aspx" rel="nofollow">SuppressMessageAttribute</a>. Now code analysis is built into the "higher" SKU's of Visual Studio but previously you had to use the tool named <strong>FxCop</strong> to perform the analysis.</p> <p>In general you have three options when you want to ignore a warning:</p> <ul> <li><p>You can remove the rule from the ruleset that you are using to analyze the code. You should only do this if you really do not care about the rule.</p></li> <li><p>You can suppress the warning in a project-wide suppression file normally named <code>GlobalSuppressions.cs</code> by using the <code>SuppressMessageAttribute</code>. This will allow you to maintain all the suppressions in a single file but makes it somewhat hard to associate a specific suppression with a piece of code.</p></li> <li><p>You can suppress the warning in the source file where it occurs using the <code>SuppressMessageAttribute</code>. This creates a clear link between the code and the suppression but also litters the code with extra information. Note that some warnings can only be suppressed in the global suppression file because they are not associated with a specific piece of code.</p></li> </ul> <p>The last two options are available directly in Visual Studio when you click on the <strong>Action</strong> dropdown on a code analysis warning. When you ignore a warning using the <code>SuppressMessageAttribute</code> you can provide a value for <code>Justification</code>. Doing that will allow you and also other developers at later point in time to understand why the warning was suppressed.</p> <p>If you get warnings about spelling because you have some special words or abbreviations in your code you should probably not suppress the warning and instead create a <a href="http://msdn.microsoft.com/en-us/library/bb514188.aspx" rel="nofollow">custom code analysis dictionary</a> for your project.</p> <p>Using code analysis on your code will not only increase the quality of your code but you might also learn a few things in the process.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload