fxcop

How to implement dispose pattern with close method correctly (CA1063)

The Framework Design Guidelines (2nd Ed., page 327) say: CONSIDER providing method Close(), in addition to the Dispose(), if close is standard terminology in the area. When doing so, it is important that you make the Close implementation identical to Dispose and consider implementing IDisposable.Dispose method explicitly. So, ...

How to write Code Analysis (FxCop) rule to prevent a method call

How do I write a code analysis tool for vs2008 to prevent a specific framework call, such as GC.WaitForFullGCComplete() or Application.DoEvents() I tried overriding the VisitMethodCall in my custom rule, but I cannot figure out what the Microsoft.FxCop.Sdk.MethodCall parameter really has in it. Could not find example on the web. Can so...

FxCop is it as valuable on VB.NET as it is on C#

I have been looking at a few of our VB.NET dll's using FxCop and all of the errors relate to DLL setup (i.e. Strong Names, Culture Info) and the case of Variables methods. Looking at a few examples of FxCop examining a C# Dll, it appears to offer a lot more potential errors. Does this mean that FxCop is more valuable on C# developmen...

How do you start with FxCop on legacy code?

Does anyone have any experience of introducing FxCop to legacy code? We would like to have our build fail if anyone introduces code that violates rules. But for the time being, this is impossible, as the legacy code has over 9000 violations. The only way to suppress errors I know of is through the SuppressMessage attribute, but that onl...

Why does FXCop thinks initializing to the default is bad?

When assigning a defualt default-value to a field (here false to a bool), fxcops says : Resolution : "'Bar.Bar()' initializes field 'Bar.foo' of type 'bool' to false. Remove this initialization because it will be done automatically by the runtime." Now, I know that code as int a = 0 or bool ok = fals...

Parameter naming: filename or fileName?

I try to be grammatically correct in my naming*. I've always used filename instead of file*N*ame. The java convention also seems to use this, but FxCop prefers fileName. There's a discussion on WikiPedia about it. The more I read, the more I feel I'm right (which is quite usual! :) ). Does anyone have a definitive answer or is this ...

FxCop rule don't compare with null value

I'm trying to write a rule for fxcop doing this: if a certain class is compared to null then error. Do you think it's possible ? I wrote a part of code descending ti the statements i could find the type i was looking for but didn't know how to find the value. for know i've got that code but dont know where to go then.. public overri...

Naming: Pricelist vs. PriceList

Which is more correct, "PriceList" or "Pricelist"? FxCop says: CA1702 : Microsoft.Naming : The compound word 'PriceList' in type name 'PriceList' exists as a discrete term. If your usage is intended to be single word, case it as 'Pricelist'. Edit: This is an object with Title, Start/End date etc. ...

How to declare event handlers to pass a FxCop rule, particularly about including sender and e?

FxCop is complaining about a event handler declaration I have. I don't see what is wrong with the code despite reading the warning several times. Code in my user control //This next line Fx Cops doesn't like. public event ImageClickEventHandler NewEntity; //A thingy defined in the BCL private void ImgBtnAdd_Click(object sender, Image...

C# Code Analysis dislikes protected static s_Foo (CA1709, CA1707)

I usually add an m_ in front of private fields and an s_ before static members. With a code like protected static readonly Random s_Random = new Random (); I get the following warnings by VS2008's Code Analysis: CA1709: Microsoft.Naming : Correct the casing of 's' in member name 'Bar.s_Random' by changing it to 'S'. CA1707: Microso...

FxCop / StyleCop for Delphi?

Does anyone know of an equivalent to FxCop/StyleCop for Delphi? I would really like to get the automatic checking of style, etc. into Continuous Integration. ...

FxCop + MVP: "Properties should not be write only"

Suppose I'm implementing an MVP pattern and I have a view interface as such: interface IView { string SuperRadString { set; } } There's no reason for the presenter to ever need to retrieve this string from the view, so can I safely ignore this error? ...

How to integrate FxCop and VS 2008?

If this is duplicated question, please point me to the proper link and I'll delete this question. I know that in VS Team System I can use Code Analysis but I'm using VS Professional. Can you tell me how I can integrate FxCop and Visual Studio? I don't want to add FxCopCmd.exe to my Post-build events to run FxCop with every compilation...

Identifiers should have correct suffix (fxcop)

I got this error for a collection I am writing, but fxcop warned me to suffix it with collection. Why? No .NET collection does this, right? i.e. List<T>, LinkedList<T>, etc. ...

FxCop and GAC Madness

Using FxCop when I try to analyze projects that rely on Patterns and Practices, Enterprise Library Data (among others) 2.0.0.0 - FxCop complains that it can’t: “Locate Assembly Reference” - even though the application dll being analyzed was complied against this version and its in the GAC. If I browse to the GAC try to select the same as...

Prevent FxCop from accessing GotDotNet

I'm running FxCop and it fails on error code 16777217. A quick Googling reveals that this is because FxCop tries to access a website at gotdotnet.com. I'm using FxCop from the command line (actually wrapped in an MsBuild community task). How do I make it not access gotdotnet site from the command line? ...

Any ideas on how to write a static analysis rule (FXCop) to ensure that event delegates are removed

We have been going through a big memory leak analysis and have found one of the contributing factors has been the non removal of delegates on events causing objects to not be GCed quickly enough (or sometimes forever). Would anyone have any ideas as to how to write a rule in FXCop to ensure that we have delegates are removed from handl...

FxCop and IComparable/IComparable<T>

I'm currently investigating the use of FxCop with one of our existing projects and am getting an odd result. The output displays a small number of breaches of the 'Override methods on comparable types' rule stating "'Log' should override Equals since it implements IComparable." There are two issues with this: I thought that it was on...

Can't get TeamCity FxCop Build Runner to Work

Any ideas as to how to make this error message go away? Cannot run process E:\Program Files\Microsoft FxCop 1.36\FxCop.exe\FxCopCmd.exe /forceoutput /gac /ignoregeneratedcode /f:\Sacog\bin\Debug\Sacog.dll /out:05A1B22A-DE6E-49ae-AA30-DC52A074EF22\fxcop-result.xml : file not found ...

Naming advice for replacing/avoiding hungarian notation in UI?

I've stopped using Hungarian notation everywhere except in the UI, where often I have a username label, a user name text box, a user name local variable, a required field validator, a user name property and method parameter so on, often all in the same context. current: lblUser, txtUser, rfvUser, _User, User, user If I do the obvious, ...