<p>In a project I'm working on FxCop shows me lots of (and I mean more than 400) errors on the InitializeComponent() methods generated by the Windows Forms designer. Most of those errors are just the assignment of the Text property of labels.</p>

<p>I'd like to suppress those methods in source, so I copied the suppression code generated by FxCop into AssemblyInfo.cs, but it doesn't work.</p>

<p>This is the attribute that FxCop copied to the clipboard.</p>

<pre><code>[module: SuppressMessage("Microsoft.Globalization",
    "CA1303:DoNotPassLiteralsAsLocalizedParameters",
    Scope = "member",
    Target = "WindowsClient.MainForm.InitializeComponent():System.Void",
    MessageId = "System.Windows.Forms.Control.set_Text(System.String)")]
</code></pre>

<p>Anyone knows the correct attribute to suppress this messages?</p>

<p>PS: I'm using Visual Studio 2005, C#, FxCop 1.36 beta.</p>

[{'answer_id': 35556, 'author': 'Matt Hamilton', 'author_id': 615, 'author_profile': 'https://Stackoverflow.com/users/615', 'pm_score': 5, 'selected': True, 'text': "<p>You've probably got the right code, but you also need to add CODE_ANALYSIS as a precompiler defined symbol in the project properties. I think those SuppressMessage attributes are only left in the compiled binaries if CODE_ANALYSIS is defined.</p>\n"}, {'answer_id': 35570, 'author': 'rjzii', 'author_id': 1185, 'author_profile': 'https://Stackoverflow.com/users/1185', 'pm_score': 2, 'selected': False, 'text': '<p>Module level suppression messages need to be pasted into the same file as the code that is raising the FxCop error before the namespace declaration or in assemblyinfo.cs. Additionally, you will need to have CODE_ANALYSIS defined as a conditional compiler symbols (Project > Properties > Build). Once that is in place, do a complete rebuild of project and the next time you run FxCop the error should be moved to the "Excluded in Source" tab.</p>\n\n<p>Also, one small tip, but if you are dealing with a lot of FxCop exclusions it might be useful to wrap a region around them so you can get them out of the way.</p>\n'}, {'answer_id': 35575, 'author': 'Scott Dorman', 'author_id': 1559, 'author_profile': 'https://Stackoverflow.com/users/1559', 'pm_score': 2, 'selected': False, 'text': '<p>In FxCop 1.36 there is actually a project option on the "Spelling &amp; Analysis" tab that will supress analysis for any generated code.</p>\n\n<p>If you don\'t want to turn analysis off for all generated code, you need to make sure that you add a CODE_ANALYSIS symbol to the list of conditional compilation symbols (project properties, Build tab). Without this symbol defined, the SupressMessage attributes will be removed from the compiled code so FxCop won\'t see them.</p>\n\n<p>The other problem with your SuppressMessage attribute is that you are listing a "Target" of a specific method name (in this case WindowsClient.MainForm.InitializeComponent():System.Void) and listing a specific "Scope". You may want to try removing these; otherwise you should add this SuppressMessage to each instance of the method.</p>\n\n<p>You should also upgrade to the <a href="http://davesbox.com/archive/2008/08/17/fxcop-1-36-released.aspx" rel="nofollow noreferrer">RTM version</a> of FxCop 1.36, the beta will not automatically detect the newer version. </p>\n'}]
['https://Stackoverflow.com/questions/35551', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2148/']