fxcop

How does one implement FxCop / static analysis on an existing code base

What are some of the strategies that are used when implementing FxCop / static analysis on existing code bases with existing violations? How can one most effectively reduce the static analysis violations? ...

Excluding FxCop rule in source.

Hi, In a project I'm working on FxCop shows me lots of (and I mean more than 400) errors on the InitializeComponent() methods generated by the Windows Forms designer. Most of those errors are just the assignment of the Text property of labels. I'd like to suppress those methods in source, so I copied the suppression code generated by F...

Why/when should you use nested classes in .net? Or shouldn't you?

In Kathleen Dollard's recent blog post, she presents an interesting reason to use nested classes in .net. However, she also mentions that FxCop doesn't like nested classes. I'm assuming that the people writing FxCop rules aren't stupid, so there must be reasoning behind that position, but I haven't been able to find it. ...

Is there a custom FxCop rule that will detect unused PUBLIC methods?

I just tried FxCop. It does detect unused private methods, but not unused public. Is there a custom rule that I can download, plug-in that will detect public methods that aren't called from within the same assembly? ...

Can FxCop/StyleCop be limited to only analyze selected methods from with Visual Studio?

I am taking on a maintenance team and would like to introduce tools like FxCop and StyleCop to help improve the code and introduce the developers to better programming techniques and standards. Since we are maintaining code and not making significant enhancements, we will probably only deal with a couple of methods/routines at a time whe...

Which are the "must follow" FxCop rules for any C# developer?

I'm planning to start using FxCop in one of our ongoing project. But, when i tried it with selecting all available rules, it looks like I have to make lots of changes in my code. Being a "team member" I can't right away start making these changes, like naming convention change etc. anyway i would like to start using FxCop with a minimal ...

Best way of using List<T> and exposing Collection<T>

I must implement a web service which expose a list of values (integers, custom classes etc). My working solution returns a List<T>, and according to FxCop it is better to return a Collection<T> or ReadOnlyCollection<T>. If I choose to return a ReadOnlyCollection<T>, the web service shows an error like: To be XML serializable, types ...

Is FxCop's CollectionPropertiesShouldBeReadOnly rule incompatible with the spring framework?

FxCop has the CollectionPropertiesShouldBeReadOnly rule that complains if your class has some kind of collection property that clients can set. Instead, it suggests making the property read-only and supplying a Clear() method and Add() or AddRange() methods for changing the contents of the collection. I agree that makes for a cleaner an...

Detect .NET Framework 3.5 SP1 Dependency (cmp. 3.5 w/o SP1)

I'm using 3.5 SP1 on my machine, while our customers currently use 3.5 without SP1. I don't know any way in VS2008 to target the solution or project to 3.5 without SP1, only the 3.5 with SP1 I have installed. If we use functions or constructors not available in 3.5 w/o SP1 the code will not work properly. That is, I want to detect at c...

Which rule from FxCop do you deactivate?

I personally don't use FxCop yet. We want to work out the unit testing first before going with code analysis. However, which rules would you permanantly deactivate? Which rules would you deactivate temporarily and in which situation? ...

What's the proper naming convention for a property 'ID' : ID or Id ?

Pretty simple question: When i have a persistable object, it usually has a property called ID (for abstract classes). So .. is the naming convention ID or Id? eg. public int ID { get; set; } or public int Id { get; set; } cheers :) PS. This is for .NET btw. FXCop conformat would be a bonus. ...

How can I find methods without an explicit access modifier?

I am using FxCop and I would like to find all the methods or variables without an access modifier explicitly defined. For example: class MyClass { int myInt = 0; internal MyClass() { } } I would like FxCop to warn me that I didn't specify what access modifier will be applied to the variable "myInt" or the class "MyClass"....

FXCop Rule for "If X = Nothing" when X is a nullable integer

1 Dim x as Integer? = Nothing 2 If x = Nothing Then 3 'this is what I think will happen 4 Else 5 'this is what really happens 6 End If The proper way to write that is "If x Is Nothing". Is there a FXCop rule that checks for this? Or better yet, can someone show me how to write my own? Jonathan ...

.NET [SuppressMessage] attributes in shipping assemblies fxcop

I wonder if people (meaning the company/developers) really care about having [SuppressMessage] attributes lying around in the shipping assemblies. Creating separate configs in the Project files that include CODE_ANALYSIS in Release mode and then yanking it off in the final build seems kind of an avoidable overhead to me. What'll be the...

VS2005 Code Analysis: CA1063 (call dispose(true) and supress finalize) - with logging.

I'm trying to adhere to the VS2005 code analysis rules for a new project. I have this method: public void Dispose() { Console.WriteLine("Dispose() called"); Dispose( true ); GC.SuppressFinalize(this); } (The console call will become a log4net call at some point, and we're always interested in logging dispose for some of o...

FxCop Custom Rule - Inspecting winform control properties

I am looking for an example of a FxCop Rule that inspects the properties of controls created. Has anyone seen one? Or know how to respond to a property set in the FxCop SDK? Rich. ...

Should I ignore InterfaceMethodsShouldBeCallableByChildTypes for WPF generated code?

When using FxCop 1.36 for a WPF application with a single window that has yet to be modified, I get the InterfaceMethodsShouldBeCallableByChildTypes error with the following details: Target : #System.Windows.Markup.IComponentConnector.Connect(System.Int32,System.Object) (IntrospectionTargetMember) Resolution : "Make 'Ma...

Exclude complete namespace from FxCop code analysis?

Is it possible to exclude a complete namespace from all FxCop analysis while still analyzing the rest of the assembly using the SuppressMessageAttribute? In my current case, I have a bunch of classes generated by LINQ to SQL which cause a lot of FxCop issues, and obviously, I will not modify all of those to match FxCop standards, as a l...

How to get the FxCop custom dictionary to work?

How is it possible to get the FxCop custom dictionary to work correctly? I have tried adding words to be recognised to the file 'CustomDictionary.xml', which is kept in the same folder as the FxCop project file. This does not seem to work, as I still get the 'Identifiers should be spelled correctly' FxCop message, even after reloading ...

Creating a custom rule in FXCop

I want to create extra rules in FXCop. Custom Rules to help ensure specific best practices like checking against inline sql. I'm really looking for good resources and examples. Thanks! ...