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
106
votes
14 answers

Why/when should you use nested classes in .net? Or shouldn't you?

In Kathleen Dollard's 2008 blog post, she presents an interesting reason to use nested classes in .net. However, she also mentions that FxCop doesn't like nested classes. I'm assuming that the people writing FxCop rules aren't stupid, so there must…
Eric Haskins
  • 8,505
  • 12
  • 38
  • 47
101
votes
12 answers

CA2202, how to solve this case

Can anybody tell me how to remove all CA2202 warnings from the following code? public static byte[] Encrypt(string data, byte[] key, byte[] iv) { using(MemoryStream memoryStream = new MemoryStream()) { using…
testalino
  • 5,474
  • 6
  • 36
  • 48
99
votes
5 answers

Stylecop vs FXcop

Has Stylecop superseded FXcop? Which product should we be using with Visual Studio 2008?
JL.
  • 78,954
  • 126
  • 311
  • 459
87
votes
6 answers

'SuppressMessage' for a whole namespace

I use underscores for my test methods for a better readability and I want to suppress FxCop errors/warnings for the whole test namespace. How can I achieve this? I played with GlobalSuppressions.cs but nothing worked: [module:…
timmkrause
  • 3,367
  • 4
  • 32
  • 59
84
votes
9 answers

Parameter naming: filename or fileName?

I try to be grammatically correct in my naming*. I've always used filename instead of fileName. The java convention also seems to use this, but FxCop prefers fileName. There's a discussion on WikiPedia about it. The more I read, the more I feel…
Steve Dunn
  • 21,044
  • 11
  • 62
  • 87
73
votes
3 answers

Visual Studio Code Analysis vs StyleCop + FxCop

I used previously StyleCop + FxCop on my Visual Studio's projects. But now I am testing Visual Studio Code Analysis tool, which is easier to integrate into MSBuild, and I have found that this tools analyses some of the rules of both FxCop and…
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
73
votes
4 answers

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…
Matthew Scharley
  • 127,823
  • 52
  • 194
  • 222
63
votes
6 answers

Why is it considered bad to expose List?

According to FXCop, List should not be exposed in an API object model. Why is this considered bad practice?
David Robbins
  • 9,996
  • 7
  • 51
  • 82
57
votes
5 answers

Running Code Analysis (FxCop > 10) on build agent without installing Visual Studio

After FxCop 10 Microsoft stopped shipping a separate installer for FxCop. Officially one can currently only run code analysis (FxCop 12.0 / 14.0 / 15.0) after installing Visual Studio 2013 / 2015 / 2017. However, we are adamant about not installing…
BatteryBackupUnit
  • 12,934
  • 1
  • 42
  • 68
47
votes
4 answers

What's with the "Afx" in StdAfx.h?

I'm just curious what Afx stands for. And what about Fx in FxCop?
Qwertie
  • 16,354
  • 20
  • 105
  • 148
42
votes
9 answers

How to get the FxCop custom dictionary to work?

How is it possible to get the FxCop custom dictionary to work correctly? I have tried adding words to be recognised to the file 'CustomDictionary.xml', which is kept in the same folder as the FxCop project file. This does not seem to work, as I…
Thomas Bratt
  • 48,038
  • 36
  • 121
  • 139
40
votes
5 answers

c# warning - Mark assemblies with NeutralResourcesLanguageAttribute

I'm getting the following warning: CA1824 Mark assemblies with NeutralResourcesLanguageAttribute According to MSDN, the cause of this is: An assembly contains a ResX-based resource but does not have the…
user429400
  • 3,145
  • 12
  • 49
  • 68
36
votes
4 answers

FxCop for .NET 4.0

I know Visual Studio 2010 has a new Code Analysis tool built in, but that is only for the premium and ultimate editions. From what I can see the latest FxCop supports .NET 3.5 SP1. Searching I wasn't able to find any references to an FxCop for…
Jim McKeeth
  • 38,225
  • 23
  • 120
  • 194
32
votes
2 answers

FxCop: Compound word should be treated as discrete term

FxCop wants me to spell Username with a capital N (i.e. UserName), due to it being a compound word. However, due to consistency reasons we need to spell it with a lowercase n - so either username or Username. I've tried tweaking the…
Anne Schuessler
  • 1,692
  • 13
  • 25
28
votes
10 answers

Which are the "must follow" FxCop rules for any C# developer?

I'm planning to start using FxCop in one of our ongoing project. But, when i tried it with selecting all available rules, it looks like I have to make lots of changes in my code. Being a "team member" I can't right away start making these changes,…
Vijesh VP
  • 4,508
  • 6
  • 30
  • 32
1
2 3
49 50