_Michael Fischer_

I have some XAML forms that generate errors in the partial file (*.g.cs). For example, the DoNotCastUnnecessrily message is generated inside of System.Windows.Markup.IComponentConnector.Connect.

Is there a way to suppress messages that occur in the generated partial file

Thank you,

Michael Fischer



Re: Visual Studio Code Analysis and Code Metrics fxcop 1.35, WPF & DoNotCastUnnecessarily

Ryley Taketa - MSFT

Hi Michael,

The only way to suppress errors within the generated *.g.cs file is with a global (module-level) suppression. Adding an in-source suppression will not work since the suppression will be lost each time the *.g.cs file is regenerated.

To add a global suppression, do the following.

If you're using FxCop:

Right-click the message in FxCop.

In the context menu, select Copy As -> Module-level SuppressMessage.

This will copy the formatted SuppressMessageAttribute to the clipboard.

Paste the copied text into a source (.cs) file included in your project.

It might be easier to manage your global suppressions if you keep them all in one file.

If you're using Visual Studio:

Right-click the message in the Error List.

In the context menu, select Suppress Message(s) -> In Project Suppression File.

This will automatically insert the correct SuppressMessageAttribute in a file named GlobalSuppressions.cs.

Thanks,

Ryley





Re: Visual Studio Code Analysis and Code Metrics fxcop 1.35, WPF & DoNotCastUnnecessarily

_Michael Fischer_

Ah, I had dismissed the Module level supression since I thought they were global and didn't know about the target attribute. Thanks. I love it when I learn something.

Michael





Re: Visual Studio Code Analysis and Code Metrics fxcop 1.35, WPF & DoNotCastUnnecessarily

Freedon Nadd

Hi,

I was woundering if it were possible to create a suppression message for all the .g.cs

For example, if I have only 1 .g.cs file: it's easy, right-click on suppress message(s) and that's it.

but if I have 1000 .g.cs file: I would have to right-click on suppress message(s) for every file.

and if I had new files, I would have to right-click...

Is there an easy way to do it

Thanks for the help.





Re: Visual Studio Code Analysis and Code Metrics fxcop 1.35, WPF & DoNotCastUnnecessarily

Todd King - MSFT

Hi Freedon,

This is a very common request and we are looking at putting this functionality into the next version of Visual Studio (the next version after VS2008 that is). Right now you need one suppression per violation, currently there is no way to use one suppression attribute to suppress multiple violations. I believe you can select multiple violations and right click to generate suppressions for them all at once instead of needing to right click for each one though.

-Todd






Re: Visual Studio Code Analysis and Code Metrics fxcop 1.35, WPF & DoNotCastUnnecessarily

DavidDylan

I'm having a similar problem with FxCopCmd 1.36 Beta 2.

Rule "CA1033:Interface methods should be callable by child types"

fires against

System.Windows.Markup.IComponentConnector.Connect(System.Int32,System.Object)

in Window1.xaml, which was created by Visual Studio 2008 Beta 2 and has not been edited.

If I look at the auto-generated code (open Window1.xaml.cs, right-click InitializeComponent and Go To Definition) that method has the attribute

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]

but if I open the exe with ILDASM that attribute isn't there. Consequently the rule still fires.

The rule fires even if I use the /ignoregeneratedcode switch. Is this a bug (or two), or am I missing something





Re: Visual Studio Code Analysis and Code Metrics fxcop 1.35, WPF & DoNotCastUnnecessarily

David M. Kean - MSFT

As the XAML is not marked as generated code, /ignoregeneratedcode will not work. However, as it already has a suppression, make sure that you are compiling your assembly with CODE_ANALYSIS defined before running it in FxCop.