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
10
votes
1 answer

Is there a way to identify unused or stale FxCop message suppressions?

We use FxCop's global suppressions to suppress rule violations found in old code. By old code I mean code that was written sometimes years before we turned on code analysis. We fix violations in new code. We cannot fix the violations in the old…
Dan Finucane
  • 1,547
  • 2
  • 18
  • 27
10
votes
7 answers

How to manage FxCop overwhelming reports

I've recently started using it. However, after running it against one of my company's largest project. It turns up mountains of problems. The list of problems was so overwhelming it would take days to find and fix some, if not all of the stuff. Now,…
chakrit
  • 61,017
  • 25
  • 133
  • 162
10
votes
3 answers

CS8019 Error on Assemblyinfo on temp file MSBuild Server

I am getting a code analysis error on my build server the error is ...NETFramework,Version=v4.6.AssemblyAttributes.cs(3,1): error CS8019:Unnecessary using directive. This is in a Temp file which Visual Studio creates. In my project I have…
MicroMan
  • 1,988
  • 4
  • 32
  • 58
10
votes
3 answers

Visual Studio Code Analysis Rule - "Do not expose generic lists"

Do not expose generic lists IF all my methods, need to expose a collection, then I need to user the Linq Extension .ToList(), almost everywhere I need to use lists, or user Collections in all my code. If that’s the case, .ToList() is ignoring the…
Fraga
  • 1,361
  • 2
  • 15
  • 47
10
votes
3 answers

FxCop installation

I am trying to get latest version of FxCop. I am using Visual Studio 2010 Professional edition which does not include code analysis, so I am trying to set it up using FxCop. At http://www.microsoft.com/en-us/download/details.aspx?id=6544 there is…
Andrija
  • 14,037
  • 18
  • 60
  • 87
10
votes
5 answers

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…
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
9
votes
1 answer

How to implement generic IEnumerable or IDictionary to avoid CA1006?

Out of curiosity i would like to know how to best implement a class that could be used to avoid the CA1006 warning CA1006 : Microsoft.Design : Consider a design where 'IReader.Query(String, String)' doesn't nest generic type 'IList(Of…
mrt181
  • 5,080
  • 8
  • 66
  • 86
9
votes
4 answers

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?
Corey Trager
  • 22,649
  • 18
  • 83
  • 121
9
votes
4 answers

How do you start with FxCop on legacy code?

Does anyone have any experience of introducing FxCop to legacy code? We would like to have our build fail if anyone introduces code that violates rules. But for the time being, this is impossible, as the legacy code has over 9000 violations. The…
Peter
  • 13,733
  • 11
  • 75
  • 122
9
votes
3 answers

How do you disable Roslyn Analyzers when using msbuild through the command line?

The Roslyn Analyzers are installed as nuget packages, which are dependencies of the FxCop Analyzers (also installed as nuget packages). I have enabled full solution analysis as instructed here: How to Enable and disable full solution analysis for…
Rich
  • 1,895
  • 3
  • 26
  • 35
9
votes
3 answers

FxCop - Use properties where appropriate

I have interface in service layer with several methods starting with Get and FxCop's Use properties where appropriate rule complains that I should consider using properties instead. I tried to use SuppressMessageAttribute but when it's defined on…
Jozef Izso
  • 1,740
  • 15
  • 22
9
votes
3 answers

Has anyone created any cool rules for FxCop/StyleCop?

I'm just looking for some inspiration. Especially in the area of performance and security, naming conventions are important but not as 'cool' ;) Even if your rule was only applicable to your domain/project but demonstrates how powerful a rule can…
tpower
  • 56,100
  • 19
  • 68
  • 100
9
votes
1 answer

.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. …
anvilis
  • 157
  • 5
9
votes
1 answer

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

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…
Arseni Mourzenko
  • 50,338
  • 35
  • 112
  • 199
9
votes
5 answers

Is fxcop a valuable/effective tool for improving code quality?

I have a large high quality c# framework codebase that I nevertheless want to try to improve. Is fxcop an effective tool for improving .NET frameworks? I know Microsoft uses the tool internally, but how do external users find it? Worthwhile? I…
Paul
  • 5,376
  • 1
  • 20
  • 19