Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling/Fixing Code Analysis warnings from .Designer.cs files

I am using DataVisualization.Charting.Chart extensively, and for the most part it is working. However, I've been running Code Analysis frequently, and have all my own warnings taken care of. But, there are about 30 CA2000 (object not disposed along all exception paths) in the *.Designer.cs files that use the charting. The Designer files are generating pretty much all the charting code, and almost all the charting elements implement IDisposable. I have "Suppress results from generated code" checked in the project preferences, but it still does it.

Is there any way to fix this, without having to manually create the chart objects, and without disabling Code Analysis for the rest of the code in that class? Is there a way to disable it for all .Designer.cs files? Or, is there a solution to remove these warnings correctly by making the designer code take care of disposal?

like image 689
drharris Avatar asked Aug 08 '11 18:08

drharris


People also ask

How do you suppress Code Analysis warnings?

If you migrate a project to Visual Studio 2019, you might suddenly be faced with a large number of code analysis warnings. If you aren't ready to fix the warnings, you can suppress all of them by selecting Analyze > Build and Suppress Active Issues.

What is suppression State in Visual Studio?

It states if a warning had been suppressed by the #Disable Warning pragma. The state of a warning is either active or suppressed if it's enclosed in a pragma.

What is pragma warning in C#?

C# provides a feature known as the #pragma feature to remove the warnings. Sometimes we declare a variable but do not use the variable anywhere in the entire program so when we debug our code the compiler gives a warning so using the #pragma we can disable these types of warnings.

How do I see warnings in Visual Studio?

To display the Error List, choose View > Error List, or press Ctrl+\+E.


1 Answers

A fair few developers appear to have encountered this without a luck, so +1 for a good question!

A possible solution is to write a method that override's CA2000 and suppresses the rule if the warning is detected in a designer file, here's a good start:

Writing Custom Code Analysis Rules in Visual Studio 2010

Otherwise see the comments at the end of this thread, MSFT engineers mention to log a Connect call: http://blogs.msdn.com/b/codeanalysis/archive/2010/03/22/what-s-new-in-code-analysis-for-visual-studio-2010.aspx

like image 126
Jeremy Thompson Avatar answered Sep 21 '22 05:09

Jeremy Thompson