fxcop

FxCop: Compound word should be treated as discrete term

FxCop wants me to spell Username with a capital N (i.e. UserName), due to it being a compound word. However, due to consistency reasons we need to spell it with a lowercase n - so either username or Username. I've tried tweaking the CodeAnalysisDictionary.xml by adding the following section to the section: <DiscreteExceptions> <Ter...

How to change FxCop language?

Is it possible to change the language of the FxCop dictionary to something other than English? How can it be done? ...

DoNotCastUnnecessarily really performance rule ?

Hi all. First, I was trying to do something like : class Class1 { public void Do() { } } class Class2 { public void Do() { } } ... if (o is Class1) { Class1 c = (Class1)o; c.Do(); } if (o is Class2) { Class2 c = (Class2)o; c.Do(); } but fxcop tells me that : Performance Rules, Avoid duplicat...

SuppressMessage in interface

Hi, I tried to suppress a particular FxCop warning for a method defined in an interface by adding SuppressMessage attribute to the method. But the warning still appears. I know the SuppressMessage attribute is the right choice. public interface ICustomerAccess { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", ...

Automatically verify some threading restrictions? (C#)

Our codebase has a lot of threading restrictions encoded in comments - such as: This class is thread-safe (all public methods may be safely accessed from any thread) Must hold a lock on "xyz" to access/invoke any public members Must only be accessed from thread "xyz" (usually but not always referring to the GUI thread) This lock must b...

Should I use FxCop and why?

I'm working on a project in C# .net and WPF. We're using StyleCop to help bring a consistent style to the project, and after disabling some rules we're quite satisfied with it. However, I've heard people talk about FxCop, and that this would bring value to the project too. From what I understand this is more on a code structure base..? ...

custom static code analysis rules in fxcop or stylecop?

if writing my own static code analysis rules (for C# code), what are the pros and cons of using stylecop vs fxcop? is one more appropriate for certain type of analysis than the other? or is the difference between the two that one runs on the source code and the other on the compiled assembly? ...

Does Code Analysis support defining two languages for mixed language Spell Checking?

Using the tip provided by José Adan at http://social.msdn.microsoft.com/Forums/en-US/vstscode/thread/f6dec8c4-9752-4a9b-82fe-0822808fd386/ I was able to get Code Analysis to do spell checking in Brazilian Portuguese. It's a common practice to mix Portuguese and English on type and member names down here in Brazil. I've also seen this pr...

VS2008: Define the same code analysis settings for a whole solution ?

I want to use the built in code analysis feature in Visual Studio 2008. The settings seems to be only set on a project level. How can I set code analysis settings globally for the entire solution ? ...

FxCop not reflecting changes

Hi all, I am trying to get my head around FxCop. (Shouldn't be that hard). I am looking at an existing project so I thought I would start with just one of the small helper libraries. It is my "common" library that has things like extension methods. The first time I ran it over the common DLL I got the following error with an extensi...

Is there a FxCop rule for local used IDisposable's?

... if I use an IDisposable in a local variable, but do not call Dispose() or use the using() pattern. public void BadMethod() { var fs = new FileStream("file.txt", FileMode.Create); fs.WriteByte(0x55); // no dispose, no using() } Just like the "Types that own disposable fields should be disposable" rule for fields. EDIT...

FxCop (or equivalent) for non-.Net C++ code

Is there a way to get FxCop to analyze unmanaged C++ code? Setting the /clr flag allowed FxCop to open the .exe. It find a LOT of C++ items, but the analysis on the code is very weak. For example, the following code was skipped: int i=0; if (i=2) printf("Don't worry..everything will be okay."); I would like a tool that can catch t...

Getting to Microsoft.Office.Interop.Word.dll?

When FxCop examines an assembly it gives the following error: The following reference assembly could not be found. The assembly is required for analysis and was referenced by Test.dll. Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c So, I did a search and found the file in: C:\Windo...

What rule do you wish FxCop/Gendarme had?

What definable static code checking rule do you wish to see added to FxCop and/or Gendarme? Why to do you wish to see the rule added, e.g what are the benefits etc? How could your rule be implemented? ...

Immutable readonly reference types & FXCop Violation: Do not declare read only mutable reference types

I have been trying to wrap my head around this FXCop violation "DoNotDeclareReadOnlyMutableReferenceTypes" MSDN: http://msdn.microsoft.com/en-us/library/ms182302%28VS.80%29.aspx Code from MSDN which would cause this violation: namespace SecurityLibrary { public class MutableReferenceTypes { static protected readonly St...

Refactoring method with many conditional return statements

Hi, I have a method for validation that has many conditional statements. Basically it goes If Check1 = false return false If Check2 = false return false etc FxCop complains that the cyclomatic complexity is too high. I know that it is not best practice to have return statements in the middle of functions, but at the same time...

FXCop casting Warning

I get the following error when running FXCop: CA1800 : Microsoft.Performance : 'obj', a variable, is cast to type 'Job' multiple times in method 'ProductsController.Details(int, int)'. Cache the result of the 'as' operator or direct cast in order to eliminate the redundant castclass instruction Code: object o...

Do not declare read only mutable reference types - why not?

I have been reading this question and a few other answers and whilst I get the difference between changing the reference and changing the state of the current instance I'm not certain why this means that I shouldn't mark it readonly. Is this because marking something as readonly tells the compiler something special about the instance an...

FXCop violation CA1716 IdentifiersShouldNotMatchKeyword - is this really a problem?

We have recently started using FxCop on our code base and I am in the process of evaluating the problems. One is the IdentifiersShouldNotMatchKeywords issue. This applies to a namespace company.blah.Event, which it wants me to change to something else as event is a keyword. The docs say: When to Suppress Warnings Do not suppress a wa...

How to validate DataReader is actually closed using FxCop custom rule?

I have written couple of custom rules in for FxCop 1.36. I have written code to find weather an opened DataReader is closed or not. But it does not check which DataReader object is calling the Close() method so I can't be sure if all opened DataReader objects are closed!! 2nd: If I am a DataReader in an 'if/else' like if 1=2 dr = cmd...