FxCop FAQ

This document discusses frequently asked questions about FxCop installation, loading and analysis, rules, and other FAQs.

Installation

Question

FxCopCmd does not work as an external tool in Visual Studio. What can be the problem?

Answer

Inspect the settings in the External Tools dialog box.

  • The value of all command-line options that contain a space must be enclosed in quotation marks (specified in the Arguments text box). This includes environment variables that when you expand them contain spaces.

  • The length of the expanded command line must be less than 255 characters.

  • Verify the command line by selecting the "Prompt for arguments" check box and running FxCop from the VS IDE. A dialog box will appear with the command line expanded.

  • Make sure that the "Use Output window" check box is selected.

Question

Can FxCop be used in a side-by-side installation of the .NET Framework?

Answer

Yes.

Loading/Analysis

Question

Why will not FxCop load some of my assemblies?

Answer

FxCop only loads and analyzes managed code assemblies. The following are the major reasons an assembly fails to load:

  • The assembly is a native binary. This generates an invalid file format exception.

  • The assembly is a COM interop assembly generated by the Type Library Importer tool (Tlbimp.exe). FxCop does not load these assemblies because they wrap non-managed code.

  • All dependencies of the target assembly could not be found. Although interop assemblies are not loaded, if they are dependencies of the target assembly, they must be located by FxCop. Look at the dependency list in the manifest using the MSIL Disassembler (Ildasm.exe).

Question

  • Why doesn't FxCop resolve the source locations of all messages?

  • I built my assemblies with debug information. Why does <PDB not available or source lookup disabled> appear in the Source field of the Message dialog box?

  • What does <Unknown File> in the Source field of the Message dialog box mean?

Answer

FxCop requires program debug database (PDB) files in order to provide source locations.

  • <Source Lookup Disabled > indicates that source file lookup is disabled in the UI.

  • <Location not stored in Pdb> indicates that either the correct PDB file cannot be located or no PDB information exists for the target element. This can occur if the PDB does not exist, does not exist in the same directory as the target assembly, or does not match the version of the target assembly. If the PDB is in a different directory, set the _NT_SYMBOL_PATH environment variable to the location of the PDB file. Another possibility is that the analyzed item is picked up from the GAC. The C# and Visual Basic .NET compilers only generate PDB information for methods and properties. Therefore FxCop cannot find the source location for programming elements such as attributes, types, or namespaces.

Question

Messages are displayed in the UI when I analyze a project. Why aren't messages written when I analyze the same project on the command-line? When I include the /summary switch, it shows that messages were generated.

Answer

The console message output depends on the report options set in the project file. By default, all active messages are written to the console. To verify this setting, from the Project menu, select Options to display the Project Options dialog box. In the Save Messages group, the Active check box for a report should be selected.

Rules

Question

I need help understanding the FxCop rules.

Answer

More information about a rule is available by double-clicking the rule and then selecting the URL link under the Support tab.

Question

I have developed some custom rules that I want to share with other people. Is there somewhere I can post these rules?

Answer

Locate GotDotNet User Samples and filter on FxCop in the "All related products" drop-down list.

Question

The message from the Virtual methods and their overrides require the same LinkDemand status rule states that I should add a LinkDemand to my code. I do not have the source code for the virtual method. How do I find which permission to link demand?

Answer

Use the Permissions View tool (Permview.exe), with the /decl option, to examine the assembly that contains the virtual method. The /decl option displays all declarative security at the assembly, class, and method level for the assembly.

Question

I have lots of CultureInfoShouldBePassed messages on code generated by the VS IDE, specifically from the InitializeComponent method of a form. The note just before the method states "do not modify the contents of this method." How can I fix these?

Is there any way of telling the Visual Studio .NET Designer to use CultureInfo.InvariantCulture?

Answer

The CultureInfoShouldBePassed rule alerts a developer to all culture-aware overloads and requires an explicit decision of whether a global audience is expected. There currently is not a way to tell the Visual Studio .NET designer to specify a CultureInfo.InvariantCulture. However, you can safely exclude these FxCop messages on code generated by Visual Studio.

Miscellaneous

Question

How can I add custom words to the FxCop dictionary? How can I add project specific dictionaries?

Answer

Create a file that is named CustomDictionary.xml. Add the following XML structure, with the new words (case insensitive) under the <Recognized> node.

<Dictionary>
    <Words>
        <Recognized>
               <Word>aNewWord</Word>
               <Word>AnotherNewWord</Word>
        </Recognized>
    </Words>
</Dictionary>

To use the dictionary with all projects, put the file in the FxCop install directory (usually C:\Program Files\Microsoft FxCop). For project-specific dictionaries, put the file in a separate directory together with the project file. For the words to be recognized, you must close and restart FxCop after you create or modifying the custom dictionary.

Question

How can we share a project/report file among our group when we have different directory/drive structures?

Answer

Instead of using the Shared Project option, which requires all files to be on the same drive, do the following:

  • Use environment variables to specify all target and rule paths.

  • Change the Report Stylesheet link (choose Options from the FxCop Project menu) to your own shared XSL document.