fxcop

FxCop TypeNode.IsDerivedFrom method works unexpectedly for types from different assemblies.

Hello I have base type "Base" in assembly "A" and derived type "Child" in assembly "B". I'm using FxCop to find in assembly "B" types derived from "Base" like this: var baseAssemblyNode = AssemblyNode.GetAssembly("A.dll"), true, true, false); var baseType = baseAssemblyNode.Types.Single(t => t.Name.Name == "Base"); var assemblyNode =...

CA1500 vs. SA1309 - Which one wins?

I'll prefix by saying that I understand that both Code Analysis and StyleCop are meant as guidelines, and many people chose to ignore these anyway. But having said that, I'd like to see what the general consensus is with regard to these two rules. Rule CA1500 says don't make parameter names and private field names the same. Rule SA130...

Troubleshoot code analysis

I try running code analysis on my solution. It fails with a generic error message that doesn't give any information. What is the best way to troubleshoot this sort of thing? For example is there a log file? ...

SuppressMessage scope=type

Hi, how can I do suppress FxCop warnings for whole type? I have Hi guys, how to suppress warnings for all members in type namespace ConsoleApplication1 { public static class Serializer<T> { public static string Serialize(T obj) { return string.Empty; } public static T Deserialize...

How to get only user created properties using microsoft.cci Members?

I'm learning T4, and am successfully interrogating my custom class for its member. What I need however, is to bring out only the properties that I created, like FirstName, Surname, and Postcode. Here's an example of what I'm actually getting when I use : foreach(Microsoft.Cci.Member member in class.Members) { if( member.IsPublic ...

Code Analysis warning CA2000: Call Dispose on object 'new ContainerControlledLifetimeManager()'

I'm getting a code analysis warning on some of my unit tests: WidgetManagerTests.cs (40): CA2000 : Microsoft.Reliability : In method 'WidgetManagerTests.TestInitialize()', call System.IDisposable.Dispose on object 'new ContainerControlledLifetimeManager()' before all references to it are out of scope. I'm using Unity ...

CA1026 (all parameters should have default values) and extension methods

Premise When using code analysis (or fxCop) with C# optional parameters you can get a warning of CA1026. The short reason1 for this is not suppling all parameters with a default value. The declaration below rightly generates this warning public Color GetColor(bool red, bool blue = true, bool green = true) However there is a situatio...

Why "Properties that return arrays are prone to code inefficiencies"?

Hi, I have a piece of code which deals with customers stored in database. There is an object Customer, and it has, among other, two properties of type byte[]: one property for password salt, the second one for password hash. Checking the code with FxCop, I see that it complains (CA1819, Performance Rules) that: "Properties that ret...

Code Analysis tool errors with "The given key was not present in the dictionary."

I get the following unhelpful error while building my .NET project when Code Analysis runs. It happens both in Visual Studio and building from the command line with MSBuild. * 1 total analysis engine exceptions. MSBUILD : error : CA0001 : The given key was not present in the dictionary. Any ideas on what is broken? Edit: Have fo...

Skip analyzing of internal types in FxCop

Is it possible to have FxCop ignore/skip analyzing of internal interfaces and classes in a given assembly? I'm not interested in specifying all public interfaces and classes to FxCop (as analyze only these). This would mean that every time a new public type is added I have to go to FxCop's configuration and add this new type. ...

FxCop 1.36 with CruiseControl.NET 1.5

I need to run FxCop with CruiseControl.NET 1.5 for continuous Integration. I have included the buildscript with the command to execute the FxCop project file. When I Build the project in CruiseControl.NET, I get the following error. C:\CPLBuildScripts\CheckpointLearning\FullBuild\Web.BuildScript.proj (19,5): errorMSB3073: T...

How to add a custom FxCop rule???

Below are my custom rule assembly and embeded xml resources file. My assembly name and the default namespace name are both MyRules. I just cannot figure out why it could be SO SO difficult to add a custom fxcop rule? I always got the "no rules were selected" error. I am going crazy... using System; using System.Collections.Generic; usin...

FxCop + command line execution?

does anyone know how to or can provide the syntax for running FxCop via command line. i want to set a task to run a defined rules.fxcop file (this is a empty project that i made with only a select set of rules enabled to reduce noise and check for things i am interested in) can someone explain how i can accomplish this... i am guessin...

FXCop warning CA1801: "Parameter is never used..." on overridden inherited supressed property

On a continued mission to clean up the codebase I inherited, via stylecop and fxcop, and one of the warnings from fxcop was CA1801: Parameter 'value' of Something.MyProperty.set(string) is never used. Remove the parameter or use it in the method body. The code it complains about is: public class Something : ISomeInterface public ne...

.NET Framework FxCop rule CA1401 PInvokesShouldNotBeVisible rule - why does this rule exist?

This rule indicates that P/Invokes should not be made public. My question is why? A caller can trivially create their own declaration within their own assembly to make the exact same call. A caller could just write a C library to call the API. What benefit, security or otherwise, is gained by making these declarations internal? ...

Is there a way to make fxcopcmd to always return 0 ?

Hello everyone ! I would like to use fxcop in a continuous build, and almost every class in my project are analysed, but there is some exception (assembly load) and it makes the fxcopcmd exit with error code 8. So the continuous build fails, because of this error code. I want the build to finish, so that i can present all the results, ...

FxCop and Teamcity: Doesn't show code or code-lines

I am trying to use the FxCop build runner in TeamCity (5.1.2) and while I get the analysis output, the errors all show '0' for the code line link and I can't open anything in the IDE using that link. I am assuming (since I have not been able to get any further) that I should be able to see the offending lines of code. Currently, I have...

FXCOP show Locate assembly eference window while analyzing

Hi, While analyzing in FXCOP, it show Locate assembly eference window. Do I need to do any setting. Thanks for help, Jaydeep ...

How to create custom static analysis rule that checks a specific property value

Hi, I would like to use the FXCop introspection API to create a custom rule that verifies the following: in MethodA, the code sets a property B on a static class C to value D : void MethodA() { C.B=D; } how can I write this? also how can I debug through a rule? ...

How can I get the value of a parameter passed to a method in a custom rule in FxCop?

Due to certain reasons, in our ASP.NET web application, it is not recommended to use Response.Redirect("something", True). It should be used with False for the endResponse parameter. We want to enforce this with a custom FxCop rule. I've managed to find the usages of Response.Redirect, but now I want to find the value of the endResponse ...