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

Is CA2007 relevant to a .NET Core application?

When I run FxCop on my project, I get a large number of warnings with the ID of CA2007. This ID is missing from the docs (it just skips from CA2006 to CA2100), but the message I get is: Do not directly await a Task without calling ConfigureAwait I…
Tom Wright
  • 11,278
  • 15
  • 74
  • 148
17
votes
3 answers

Why can't Microsoft analyzers find Microsoft.CodeAnalysis?

I'm trying to add Microsoft.CodeAnalysis.FXCopAnalyzers (latest stable version) to my ASP.NET project. When I install it via NuGet, I get a ton of errors like: An instance of analyzer…
Brian Gradin
  • 2,165
  • 1
  • 21
  • 42
17
votes
1 answer

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…
Steve Dunn
  • 21,044
  • 11
  • 62
  • 87
17
votes
3 answers

How to suppress code analysis messages for all type members?

Let's say I have an enumeration of all currencies: public enum CurrencyType { /// /// United Arab Emirates dirham /// [EnumMember] AED = 784, /// /// Afghan afghani ///
penartur
  • 9,792
  • 5
  • 39
  • 50
16
votes
2 answers

How do you "properly" implement Dispose() (according to FxCop) when your implementation is an empty method? (CA1063)

I have an implementation of an interface, and that interface extends IDisposable. In my particular implementation of the interface, I don't need to dispose anything, so I just have an empty Dispose() method. public interface IMyStuff :…
CodingWithSpike
  • 42,906
  • 18
  • 101
  • 138
16
votes
5 answers

CA1819: Properties shouldn't return arrays - What is the right alternative?

I encountered this FxCop rule before and wasn't really content with how to solve violations (thread1, thread2). I now have another case where I need to correct violations of the CA1819 kind. Specifically, I have an algorithm-library that performs…
Efrain
  • 3,248
  • 4
  • 34
  • 61
16
votes
4 answers

CA2213 code analysis rule and auto-implemented properties

I use static code analysis in our projects to check for code violations. One of extensively used rules is CA2213, which checks for correct disposing of disposable fields. I noticed CA2213 does not check disposing of auto implemented properties.…
Zvonko
  • 363
  • 2
  • 19
14
votes
3 answers

How to integrate FxCop and VS 2008?

If this is duplicated question, please point me to the proper link and I'll delete this question. I know that in VS Team System I can use Code Analysis but I'm using VS Professional. Can you tell me how I can integrate FxCop and Visual Studio? I…
Vadim
  • 21,044
  • 18
  • 65
  • 101
14
votes
5 answers

Should GC.SuppressFinalize be called on objects that do not have a finalizer?

For some reason FXCop seems to think I should be calling GC.SuppressFinalize in Dispose, regardless of whether I have a finalizer or not. Am I missing something? Is there a reason to call GC.SuppressFinalize on objects that have no finalizer…
Sam Saffron
  • 128,308
  • 78
  • 326
  • 506
14
votes
2 answers

What Replaces Code Analysis in Visual Studio 2019?

I'm toying with getting our team and projects ready for VS 2019. Right away, trying to set up Code Analysis for a new project, I find this: So, if this is deprecated (and apparently can't even be used, so I'm thinking "deprecated" really means…
14
votes
3 answers

Tell FxCop another method is calling dispose

Typically when you dispose a private member, you might do the following: public void Dispose() { var localInst = this.privateMember; if (localInst != null) { localInst.Dispose(); } } The purpose of the local assignment is to…
Haacked
  • 58,045
  • 14
  • 90
  • 114
13
votes
2 answers

CA1726: FxCop Forbidden Word: Flags

someone wants me to make other people's code compliant to some FxCop ruleset which includes rule CA1726:Use preferred terms. Most of the terms/replacements are all right and I can understand that one has to decide on one single way to name…
Efrain
  • 3,248
  • 4
  • 34
  • 61
13
votes
1 answer

What is the advantage to use the Microsoft.CodeAnalysis.FxCopAnalyzers nuget over the default Managed Binary Analysis ruleset?

I currently use the Managed Binary Analysis and it looks like the nuget adds the same rules (maybe less). I also use this SonarQube plugin: https://github.com/SonarQubeCommunity/sonar-fxcop. What is the nuget for exactly?
Shay
  • 183
  • 2
  • 13
13
votes
3 answers

How to run .NET 4 code analysis on build server

On a Windows Server 2003 R2 with .NET 4 SDK but without Visual Studio 2010, I have tried building a Visual Studio 2010 solution with msbuild MySolution.sln /p:RunCodeAnalysis=true but that fails. What is required to run code analysis on such an…
Ole Lynge
  • 4,457
  • 8
  • 43
  • 57
13
votes
2 answers

Code Analysis/FxCop CA1726:UsePreferredTerms showing Cancelled as Deprecated

I'm in the UK where we spell Cancelled with two L's. I want to use the Code Analysis rule "CA1726:UsePreferredTerms" but I don't want it to flag up "Cancelled" as a violation. I have tried adding en-GB to…
user1069816
  • 2,763
  • 2
  • 26
  • 43
1 2
3
49 50