fxcop

How to create custom FXCop 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; } what i would like is that inside override ProblemCollection Check(member m) I want to check: if m == MethodA { Assert: m assign...

FXCop Suppress Warning CA1800 (Unnecessary Casts)

I have the following code: [SuppressMessage( "Microsoft.Performance", "CA1800:DoNotCastUnnecessarily" )] private static void SetTestConnectionString( Component table ) { if( table is Object1 ) { fn1( (Object1)table ); } // ... a few more if statements for different Classes } However, when I run FxCop over this ...

How to fail TFS build based on FXCop warning

We are currently using TFS 2008 for source control and continuous integration. We use FXCop to check for checking performance and security warnings. The Architect or senior developer runs FX Cop at the end of a sprint or before a delivery. We would like this to run as part of the CI and fail the build if there is a warning, what is the...

FxCop rule for string == ?

Hey all, Can anyone point me to an fxcop rule for identifing "string ==" usage. For example: string s = "abc"; if (s == "def") { // do somethign } I want the "if" statement raised as an error. Roughly speaking I want to always be using string.compare with the appropriate culture. Thanks! ...

FxCop - can it be told to ignore LINQ to SQL classes?

Possible Duplicate: Exclude complete namespace from FxCop code analysis? I'm running FxCop as a post-build step of my class library project and it's picking up violations from the LINQ-to-SQL generated code. I am running FxCop as follows (line breaks added for clarity): <PostBuildEvent> "$(SystemDrive)\Utils\DeveloperTools...

How can I walk the method call to an Action, Func, or Delegate in introspector for a custom rule?

I'm writing a custom rule to verify the constructor of any control type calls initialize component. But when I hit these 2 edge cases: public Form1(int? testInt,bool testBool,bool testBool2) : this(false) { Action init = ( ) => InitializeComponent( ); init(); } public Form1(int? testInt, bool testBoo...

Make an FxCop project output an XML file (it does not output anything useful) when run with fxcopcmd.exe

Hi! When not using an FxCop project, this works: "c:\Program Files\Microsoft FxCop 1.35\fxcopcmd.exe" /file:SiteSeeker.Core\bin\Release\SiteSeeker.Core.dll /file:SiteSeeker.CoreTest\bin\Release\SiteSeeker.CoreTest.dll /file:SiteSeeker.Example\bin\SiteSeeker.Example.dll /file:SiteSeeker.Web.WebForms\bin\Release\SiteSeeker.Web.WebForms.d...

How do I suppress FxCop rule 'DoNotCatchGeneralExceptionTypes' with SupressMessage?

I've got code that catches everything and logs it. I don't normally do this, but I'm writing an HTTP handler and want to return an appropriate HTTP code. Anyway, I'm putting the following at the top of my method: [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "We just log the exception ...

Is there a clean way to read the config file during a custom rule (code analysis/Tfs check-in policy)?

I'm thinking of trying the following ideas: System.IO Package.GetGlobalService(typeof(EnvDTE.DTE)) public override Microsoft.FxCop.Sdk.ProblemCollection Check(Microsoft.FxCop.Sdk.Resource resource), while blocking on the thread that does Check(TypeNode type) until the resource reading completes. Anyone know if any of these will be re...

Module level suppression in source code of FxCop warnings

Hi, Placing this in our AssemblyInfo.cs: [module: SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope="member", Target="Foo.CoreTest.StringUtilTest.CapitalizeNull():System.Void")] Results in CA1822 being excluded for the method Foo.CoreTest.StringUtilTest.CapitalizeNull. However we would like CA1822 to be exc...

FxCop, exclude a rule from an assembly (but use it for the other assemblies)

Hi! I would like to exclude CA1822:MarkMembersAsStatic from the CoreTest assembly as the NUnit test methods cannot be converted to static methods as NUnit won´t execute them if I do. In the other assemblies I would like to have this rule as I have found it valuable. If it is possible I do not like to add a SuppressMessage to each test ...

How to check if Thread code runs in try-catch block

I would like to validate our code and check if every Thread that we execute runs in try catch block. A valid sample: Thread loadDataThread = new Thread(new ThreadStart(LoadData)); public void LoadData() { try {/*do something*/} catch(Exception ex) { /*Handle exception*/ } } Not valid sample: Thread loadDataThread = new Thread(...

FxCop is not respecting my excludes

I am trying to incorporate FxCop directly into my build. I am using the MSBuild Community Tasks. I have a targets file like this: <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt; <PropertyGroup> <FxCopToolPath Condition="'$(FxCopToolPath)' == ''">$(MetaSharpL...

fxcop fails because of references on obfuscated assemblies

Hello I need to run fxcop on a project that references an obfuscated commercial assembly (from dotnetremoting.com). Fxcop tries to load the obfuscated assembly and fails... I have got exactly the same problem with Mono Gendarme. It also tries to analyse referenced assemblies and fails. Thanks in advance for your responses Alex ...

How to use same FxCop rules in all developers?

All our developers are using VS2010 professional so code analysis is not available. I want them to use FxCop to analyze the code before checking in. I have gone through the rules and disabled a bunch of them and added couple of them. I want all the developers to use same set of rules since it will be the rules used in MSBuild. How do I d...

TeamCity and FXCop version 10

We are trying to get our TeamCity 5.1 installation to use our FXCop project file. It apparently does not like the newest version, V10: [08:26:33]: Failed loading FxCop project. [08:26:33]: Error text: This project file is version 10.0 but the current application version is 1.36. Please download a more recent version of FxCop to open th...

How can I mark a CA [SuppressMessage] as "blessed"?

Try as I might to keep [SuppressMessage]s to a minimum in the codebase, new ones continue to get introduced. I would like some way to say in the code "I've reviewed this [SuppressMessage] and it is 'acceptable'". One thought was to create my own My.CodeAnalysis.SuppressMessageAttribute class which inherits from System.Diagnostics.CodeA...

CA1804: declares a variable never used

I have a foreach loop that declares a variable I never use, but I don't know how to get around it. foreach (string i in stringCollection){ some other stuff } I never use "i" - but I need an iterator in the loop. So how do I get rid of this error? ...

FX Cop still erroring after i suppress

<System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference", Justification:="Needs function to return two values.")> _ <System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification:="Needs function to return two values.")> _ I am trying ...

Fxcop custom rule for identifying if conditions

hi how can i write a custom rule to identify an expression in an if condition? Kindly help me in this. ...