Performing an Analysis

 

To analyze assemblies, FxCop requires the following information:

         One or more target assemblies to be analyzed.

         One or more rules. FxCop enables a default set of rules in new projects.

 

To get started, simply specify the managed code assembly (executable file or DLL) to analyze.

 

To specify an assembly and run an FxCop analysis

1.      Start FxCop from the Start menu, or double-click FxCop.exe in the installation directory.

2.      From the Project menu, select Add Targets.

3.      Browse to the assembly to add, and click Open.

4.      Start the analysis using one of the following methods:

         Click the Analyze button on the toolbar.

         From the Project menu, select Analyze.

         Press the F5 function key.

 

When analysis starts, the "Analyzing with engine" dialog box appears, showing a progress meter and a Cancel button. The label of the dialog box includes the name of the analysis engine in use. When analysis completes, the analysis report is displayed in the messages pane. If there are no messages, this pane is empty.

 

Canceling an Analysis

Analysis can be canceled at any time, but analysis results might be compromised. To cancel an analysis, click the Cancel button in the "Analyzing with engine" dialog box. This brings up the Analysis Summary dialog box, which displays analysis statistics and error messages.

A message is always in one of the following states: active, excluded, or absent. (For a detailed discussion, see Message States.) When an analysis starts, all messages in the Active state are changed to the Absent state; individual messages are then changed back to Active as they are re-encountered. Any messages not re-encountered before analysis is canceled remain in the Absent state, compromising the analysis results. Excluded messages are unaffected.

 

Viewing a Summary of Analysis Results

During an analysis, FxCop gathers statistics and catches exceptions thrown by rules. Rule exceptions do not prevent an analysis from continuing, unless the total number of exceptions exceeds the limit specified for the project; however, the message report is usually incomplete. For information on setting the exception limit, see Setting Project Options.

If an analysis generates any errors, the Analysis Summary dialog box is displayed after the analysis completes. At any other time, select the Analysis Summary command from the Project menu to manually view a summary of the most recent analysis. The following screen shot shows a sample analysis report as it appears in the Analysis Summary dialog box.

 

Analysis Summary dialog box

 

The report displays the number of messages generated, the analysis start time, and the duration of the analysis. The summary report also indicates any problems FxCop encountered while performing the analysis.

 

Rule Errors

Click the bottommost Details button in the Analysis Summary dialog box to display the Rule Error(s) dialog box, which is shown in the following screen shot. The top pane shows the rules that raised exceptions while analyzing a target. Expand a rule to display the list of errors generated by that rule. Select an error and the bottom pane shows a tree view of the target that the rule was analyzing when it generated the error. Double-click the target and the corresponding target is highlighted in the Targets tree of the Configuration pane.

 

Rule Error(s) dialog box

 

Analysis Errors

Click the topmost Details button in the Analysis Summary dialog box to display the Analysis Error(s) dialog box, which is shown in the following screen shot.

 

Analysis Error(s) dialog box

 

The most common analysis problems are: 

         The current project has no targets selected.

         The current project has no rules selected.

         An assembly referenced by a target could not be located for analysis.

 

The vast majority of analysis errors are caused by a missing assembly. During analysis, the types referenced by an assembly must be available to FxCop. When FxCop cannot locate a type, an exception is reported for the assembly containing the type; its message is "File or assembly name SomeAssembly, or one of its dependencies, was not found." To fix this problem, add the missing assembly to the directory containing the assembly being analyzed, or add it to the global assembly cache. For information on the global assembly cache, see the .NET Framework SDK documentation, or visit the Microsoft Developers Network Library on the Internet.

If all managed assemblies are apparently accounted for and this error remains, a missing native dependency might be the cause. This is most common for Managed Extensions for C++ assemblies.

For other errors, such as those accompanied by the message "Type SomeType could not be loaded.", use the Assembly Binding Log Viewer (Fuslogvw.exe) shipped with the .NET Framework SDK to determine the cause of the problem. This tool provides detailed information on assembly loading failures.

 


Contact the FxCop team.

2002 - 2004 Microsoft Corporation. All rights reserved.