fxcop

FXCop: "Types that own disposable fields should be disposable"

I started messing around with FXCop against some of my assemblies and noticed something interesting that I'm trying to wrap my head around. "Types that declare disposable members should also implement IDisposable. If the type does not own any unmanaged resources, do not implement a finalizer on it." I have my own class that...

FXCop - Referenced assembly could not be found

I'm trying to use Microsoft FXCop Version 1.36 on a compact edition application but when I analyze the project I get the following error. The following referenced assembly could not be found. This assembly is required for analysis and was referenced by application.exe System.Windows.Forms, Version=3.5.0.0, Culture=neutra...

using FXCop in your project

Are there a lot of IT shops utilizing FxCop for writing production code? If so, what was/is your overall experience implementing it in terms of culture shift, pain points, and tangible benefits? I am in an environment that is somewhat chaotic and looking for tools to help us standardize our development efforts and get us home at a dece...

How do I extend a WinForm's Dispose method?

I am getting this warning from FxCop: "'RestartForm' contains field 'RestartForm.done' that is of IDisposable type: 'ManualResetEvent'. Change the Dispose method on 'RestartForm' to call Dispose or Close on this field." Ok, I understand what this means and why this is what needs to be done... Except System.Windows.Forms.Form doesn'...

CA1062: ValidateArgumentsOfPublicMethods on co-constructor calls

I have a class with two constructors that look like this: public MyClass(SomeOtherClass source) : this(source, source.Name) { } public MyClass(SomeOtherClass source, string name) { /* ... */ } When I run FxCop, it correctly reports a violation of CA1062: ValidateArgumentsOfPublicMethods, because if source is null in the first construc...

FxCop introspection engine

I am receiving an exception when I try to use the introspection engine: Could not load file or assembly 'Microsoft.Cci, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. An attempt was made to load a program with an incorrect format. Anyone got this exception? ...

Is it possible from within the csproj file to know whether devenv or msbuild is used to run it?

Motivation: I have fxcop integrated in the build process, which makes fxcopcmd.exe run each time the target has changed or as long as there are warnings from the previous run of fxcop. But when one works in the studio, devenv.exe often decides to compile the project in background for whatever reasons. For example, when I add a new proje...

Parsing FxCop logfile - how would you do it?

I'm currently writing a tool that parses the FxCop logfile on a large codebase. My goal is to provide graphical information about the most common warnings, sorted by namespace (subsystems of the application). See example graphic. This can then be used to start a discussion about which FxCop rules we care about and what actions should b...

what does this security warning mean (.Net Process class)?

Hello everyone, I am using VSTS 2008 + .Net 2.0 + C#. And I am running Code Analysis after build. I got the following confusing security warning. Here is the warning and related code, any ideas what is wrong? If there is security warning, how to fix it? System.Diagnostics.Process myProcess = new System.Diagnostics.Proce...

Overridable Methods In Constructors -Help to Fix

Hi all, Im attempting to use fxCop on a C# Project as kind of basis for C# coding standards. The project Im using is called S#arp Architecture and is freely available here: S#Arp Arch Now if I run fxCop (most things have been fixed already) I need to fix the CA2214 fxcop error for overridable methods in contructors. At the moment a p...

Overridable methods in constructors with InitMembers()

I have carried the method here on almost all of the areas where I have had overridable methods and managed to fix them but there is one part where the method doesnt work in the same way on a different contexted piece of code: public Employee() { this.InitMembers(); } private void InitMembers() { // I...

FxCop - CA1034 error - WHY?

I am running static code analysis with FxCop 1.36 and I keep getting warning CA1034: NestedTypesShouldNotBeVisible. I would understand if the parent class were declared as internal or private, but it is public. Why would it be bad for TimerReset to be declared public? Am I missing something, or is this something that can be ignored?...

Where to get a complete list of FxCop warnings sorted by code?

I'm familiar with the MSDN list, but I would like to have a list sorted by code. A lot of our developers don't have easy internet access, and it would be nice if I could give them a off-line complete list of the warnings. I would like them sorted by warning code, because that is how they identify the issues in the Fxcop logfile. ...

Why is FxCop raising the error "Types that own disposable fields should be disposable" on a class with no disposable fields?

I have a LINQ object with an additional method added to it. The class has no disposable properties or methods, but FxCop is raising the error "Types that own disposable fields should be disposable" and referencing that class. I've reduced the code this far and still receive the error: partial class WikiPage { public PagePermission...

FxCop spell check trips on company name in namespace

I am trying out FxCop (through the UI for the moment, not included in CruiseControl.NET etc.) and am running into some issues. It seems the spell checker does not like my client's company name and the product name and it asks me to: Correct the spelling of 'CompanyName' in namespace name 'CompanyName.Product.TimerJobs.FeatureReceivers'...

FxCop taking issue with my use of format strings in resources with NON-Team System Visual Studio

I ran FxCop on one of the projects that I am working on and I got a whole slew of warnings that look like the following: CA1703 : Microsoft.Naming : In resource 'MyProject.Properties.Resources.resx', referenced by name 'MyString', correct the spelling of 'Myyyy' in string value 'Some format string: {0:dMMMyyyy}' As Reso...

The Window Sitter project -- something better than a timer?

For my window sitter project (remember that one question about colorkeying?) I'm currently using a Timer to update the character's position, like I did with the original VB6 version. There are, however, a few problems with this approach: If you switch windows or move the foreground window fast enough, the character lags unless you set t...

How do you implement IDataRecord properly if IndexOutOfRangeException is a reserved exception type?

According to the documentation for IDataRecord, the implementing methods must throw IndexOutOfRangeException if the field index is out of the range of fields. However, if you try to throw an IndexOutOfRangeException directly in code, FXCop complains that it is a reserved exception type. How do you keep to the IDataRecord exception contra...

Should FxCop 'Specify IFormat Provider' catch Int32.TryParse violations?

The FxCop Globalization Rule, 'Specify IFormat Provider', does not catch Int32.TryParse violations for me. Is this a bug, or am I doing something wrong? ...

Does identifier casing really matter?

FxCop thought me (basically, from memory) that functions, classes and properties should be written in MajorCamelCase, while private variables should be in minorCamelCase. I was talking about a reasonably popular project on IRC and quoted some code. One other guy, a fairly notorious troll who was also a half-op (gasp!) didn't seem to agr...