FAQ: How do I prevent FxCop 1.36 from firing warnings against generated code?

I’ve upgraded from FxCop 1.35 to 1.36 and now FxCop has started to fire warnings against typed DataSets and other generated code. How do I turn this off? The reason this is occurring is because we changed the way that FxCop analyzed generated code. Whereas previously in 1.35, FxCop would only ignore particular generated code…

6

FAQ: Which Code Analysis rules shipped in which version?

In response to a lot of recent requests, we’ve put together a complete list of rules that shipped in the different versions of Visual Studio Code Analysis and FxCop. Attached is an Excel worksheet providing this information for Visual Studio 2005, Visual Studio 2008, FxCop 1.35 and FxCop 1.36 Beta. One of things you’ll notice…

11

Code Analysis FAQ

Find answers to commonly asked questions about Visual Studio Code Analysis. General FAQ: Why is FxCop 1.32 not available for download?FAQ: Why does FxCop generate violations against itself? Analysis and Rules FAQ: Why is file and line information available for some warnings in FxCop but not for others?FAQ: Why does FxCop warn against catch(Exception)?FAQ: Why…

0

FAQ: How do I debug a custom rule?

While writing your custom rule, you will likely come across a need to debug it and work out why it’s behaving in a particular manner.Debugging within FxCop  Debugging a custom rule within the FxCop UI is actually quite easy. To do so, simply: Open the FxCop project that contains your custom rule (making sure the PDB…

3

FAQ: Why is file and line information available for some warnings in FxCop but not for others?

It appears that sometimes FxCop displays a link to the source line and file in the Message Details window and sometimes it doesn’t. Why this inconsistent behavior? There are three usual reasons why this occurs: Source lookup is disabled. To turn source lookup on, choose Project -> Options and check Attempt source file lookup. The Program…

1

FAQ: How do I get the SourceContext for a local?

I want to fire on the naming of a local, however, whenever I pass the local to the Problem constructor, the source information for the method is always used. How do I get FxCop/Code Analysis to use the source information for the local instead? Because the declaration of a local is not associated with an executable instruction, a…

5

FAQ: How do I run FxCop during a post-build event?

A little known feature of FxCop (in particular FxCopCmd.exe) is its ability to be integrated into the build process within Visual Studio. Although not a replacement for the Code Analysis functionality available within both Visual Studio Team Edition for Developers and Visual Studio Team Suite, it allows you to display FxCop violations within the Error…

3

FAQ: When looking at the names of locals in a custom rule, why do I see strange names such as ‘CS$1$0000’ and ‘VB$1$0000’?

Previously we showed you how to access the locals or variables of a method. Once you started to run your rule over an assembly, you might start to notice strange locals with names that start with ‘CS$’ and ‘VB$’. These are compiler generated locals that are outside the control of the user. If you are…

0

FAQ: What exception should I throw instead of the reserved exceptions that DoNotRaiseReservedExceptionTypes warns against?

Throwing a general exception type such as System.Exception or System.SystemException in a library or Framework forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle (see FAQ: Why does FxCop warn against catch(Exception)? for reasons as to why this is bad). Instead, either throw a more derived type that already…

14

FAQ: How do I fix a violation of MovePInvokesToNativeMethodsClass?

MovePInvokesToNativeMethodsClass fires on P/Invokes (ie methods marked with DllImport) that are not members of one of the following classes; NativeMethods, SafeNativeMethods or UnsafeNativeMethods. For example, the following sample fires this warning.[C#]using System;using System.Runtime.InteropServices; internal static class Directory{    // Violates MovePInvokesToNativeMethodsClass    [DllImport(“kernel32.dll”)]    internal static extern bool RemoveDirectory(string name);}[Visual Basic] Imports SystemImports System.Runtime.InteropServices Public NotInheritable Class Directory    Private Sub New()    End Sub     ‘…

2