I use the FxCopCmd tool for static code analysis. Since we already had a huge code base, we based our existing problems using the baseline.exe tool that comes with FxCop.
I observe that if I add a new method to my C # class, some of the suppression files in the GlobalSuppression.cs file will stop working, and I get problems for the code that I did not touch.
Example:
namespace ConsoleApplication1 { class Program { public async Task<string> method1() { string a = ""; a.Equals("abc", StringComparison.InvariantCultureIgnoreCase); return a; } static void Main(string[] args) { } } }
This causes the following error:
CA1031: Microsoft.Design: Change 'Program.d__0.MoveNext ()' to catch a more specific exception than the 'Exception', or reconstruct the Exception
To suppress the CA1309 UseOrdinalStringComparison problem, I added the following suppression message in the GlobalSuppression.cs file
[module: SuppressMessage ("Microsoft.Globalization", "CA1309: UseOrdinalStringComparison", Scope = "member", Target = "ConsoleApplication1.Program.d__0.MoveNext ()", Code = "System.String.Equals (System.String, System.StringComparison) ", Justification =" ")]
But if I add another method to the class, this message will stop working. This is because method1 is asynchronous, and so a new class is created ( referenced by this ) in the compiled code (which was <method1>d__0
in the first case), but when I add another method before method1, a new class created in The compiled code is called <method1>d__1
. Therefore, the suppression message is not applied, and FxCop again starts to show errors in the code.
Is there a way to suppress FxCop errors for asynchronous methods permanently?