Blog Articles

Static Code Analysis with FxCop

Static Code Analysis is like spell checking for your code. Instead of looking for spelling mistakes, it looks for coding mistakes (not disposing unmanaged resources, using deprecated assemblies, globalization issues and more). For the .NET framework, the tool is FxCop. This tool works against 1.0, 2.0, and 3.x object code (assemblies, not source code). This means that the tool works for ALL CLR languages (VB.Net/C#/F#/RPG.Net...) and provides a report on nine areas of code compliance with Design Guidelines

  1. Design
  2. Globalization
  3. Interoperability
  4. Mobility
  5. Naming
  6. Performance
  7. Portability
  8. Security
  9. Usage

This tool has both a GUI and command line interface (perfect for continuous build processes) and exports an XML/HTML report. To use this tool, you will need to add the CODE_ANALYSIS compilation flag to your project. As you review your reports, you will see three types of errors

The fixes for these errors are also different

I have found tools like these to be most useful when you are hitting a wall about how to redesign or extend your application. This provides an impartial look at your code to ensure you are developing with the Design Guidelines in mind. Of course, a tool like this is also useful when you want to clean up a poorly maintained library as well!


Article Tags