Questions tagged [fxcop]

Microsoft's free static analysis tool for analyzing .NET managed code assemblies.

FxCop can be used to find coding design issues quickly and early, comes with switchable rulesets, and supports the creation of custom rules.

Available with certain versions of Visual Studio and as part of the Windows 7 SDK, available here.

749 questions
8
votes
1 answer

FxCop / Code Analysis with VS2010 Ultimate

I've getting some information about this, but I still can find a proper answer, I was asked recently in my company for this : "run a fxcop analysis on that code and tell me the results". Ok, I have VS2010 Ultimate which has code analysis, but…
Luis
  • 5,786
  • 8
  • 43
  • 62
8
votes
3 answers

How can the cyclomatic complexity be 27 in a method with 13 event handler subscriptions?

We have this code, sortof: private void InitializeEvents() { this.Event1 += (s,e) => { }; this.Event2 += (s,e) => { }; this.Event3 += (s,e) => { }; this.Event4 += (s,e) => { }; this.Event5 += (s,e) => { }; this.Event6 +=…
Johann Gerell
  • 24,991
  • 10
  • 72
  • 122
7
votes
4 answers

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…
Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
7
votes
1 answer

CA2000: object not disposed along all exception paths

Although topic has been discussed here before, but the proposed solutions don't seem to work.. I have a button-click-callback method in my form application, that shows a folder picker dialog: private void ButtonSelectReporterFolderClick(object…
Efrain
  • 3,248
  • 4
  • 34
  • 61
7
votes
1 answer

How to get the method actually called by the callvirt IL instruction within FxCop

I'm still trying to get my FxCop rule working. As part of this, i need to work out what methods a method calls. Previously i was using CallGraph.CallersFor() (doing it in reverse, which is my final aim anyway), however it appears to have the same…
George Duckett
  • 31,770
  • 9
  • 95
  • 162
7
votes
3 answers

FxCopAnalyzers: An instance of analyzer cannot be created

I'm trying to install fxcop analyzers in my project. However, having added and restored the nuget package, building the project results in hundreds of warnings of the form 1>CSC : warning CS8032: An instance of analyzer…
chtenb
  • 14,924
  • 14
  • 78
  • 116
7
votes
1 answer

Why am I getting CA2000 with a private member IDisposable inside my IDisposable class?

I have a class that implements IDisposable because it has a private member field "foo" that is IDisposable (which is initialized in the constructor). I am unexpectedly getting a CA2000 Code Analysis error, which wants me to be sure to dispose of…
Patrick Szalapski
  • 8,738
  • 11
  • 67
  • 129
7
votes
3 answers

Suppressing Static Code Analysis Warning CA1806 for TryParse calls

I was wondering what people's thoughts were on the CA1806 (DoNotIgnoreMethodResults) Static Code Analysis warning when using FxCop. I have several cases where I use Int32.TryParse to pull in internal configuration information that was saved in a…
Tim
  • 1,814
  • 8
  • 29
  • 41
7
votes
1 answer

CA1303 Retrieve the following string(s) from a resource table instead: "Service Started"

I got below violation in FxCop. when I hard code the string in Console.WriteLine("Service Started"); Method 'method()' passes a literal string as parameter 'value' of a call to 'Console.WriteLine(string)'. Retrieve the following string(s) from a…
user6874415
7
votes
1 answer

FxCop: Suppression message for async method

I am using FxCopCmd tool for static code analysis. Since we already had a huge codebase, we baselined existing issues using baseline.exe tool that comes with FxCop. I am observing that if I add a new method to my C# class, then some of the…
Gaurav Deshmukh
  • 381
  • 3
  • 15
7
votes
2 answers

Cannot run Code Analysis Analyzer in Visual Studio 2015

I installed Microsoft.CodeAnalysis.CSharp.FxCopAnalyzers from nuget into a project. The project it is installed into is an existing project, building against Framework 4.5.1. Code Analysis is Enabled on the project... ... and I see CA warnings in…
NikolaiDante
  • 18,469
  • 14
  • 77
  • 117
7
votes
1 answer

FxCop and Code Analysis in Visual Studio 2013

I want to do code analysis in my project and I am using Visual Studio 2013. I can see a Analyze tab which will help to do the code analysis. So my questions is below Should I install FxCop or shall I continue using the inbuilt Code Analysis from…
Midhun Murali
  • 2,089
  • 6
  • 28
  • 49
7
votes
3 answers

Should I suppress CA1062: Validate arguments of public methods?

I've recently upgraded my project to Visual Studio 2010 from Visual Studio 2008. In Visual Studio 2008, this Code Analysis rule doesn't exist. Now I'm not sure if I should use this rule or not. I'm building an open source library so it seems…
brickner
  • 6,595
  • 3
  • 41
  • 54
7
votes
5 answers

Immutable readonly reference types & FXCop Violation: Do not declare read only mutable reference types

I have been trying to wrap my head around this FXCop violation "DoNotDeclareReadOnlyMutableReferenceTypes" MSDN: http://msdn.microsoft.com/en-us/library/ms182302%28VS.80%29.aspx Code from MSDN which would cause this violation: namespace…
ram
  • 11,468
  • 16
  • 63
  • 89
7
votes
4 answers

What rule do you wish FxCop/Gendarme had?

What definable static code checking rule do you wish to see added to FxCop and/or Gendarme? Why to do you wish to see the rule added, e.g what are the benefits etc? How could your rule be implemented?
Ian Ringrose
  • 51,220
  • 55
  • 213
  • 317