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

Any reason not to enable CODE_ANALYSIS in production builds?

Are there any performance costs when static code analysis is enabled in a production (release) build? Our CI server runs code analysis on a debug build of our C# projects, whereas the release build has static code analysis disabled (i.e.…
7
votes
1 answer

What can go wrong when throwing a reserved exception in C#?

FxCop issues a violation of rule CA2201 if you throw System.IndexOutOfRangeException in your code (see reference). The rationale for this is that System.IndexOutOfRangeException is "reserved and should be thrown only by the common language runtime"…
Paul Jansen
  • 1,216
  • 1
  • 13
  • 35
7
votes
2 answers

Cyclomatic complexity count of 31, where has this come from?

I'm developing an application that pulls data from an Excel file (I don't have access to the actual database) and I've written a method which has as its only function to pull the data from the Excel Spreadsheet, as seen below. private…
Jake Hendy
  • 303
  • 3
  • 18
6
votes
3 answers

FxCop Complaint: Exposed concrete xml types and a bad improvement

I want to save certain classes and since xml-serialization won't do it in my case i'm saving the values manually into an xml-document. Works fine, but FxCop doesn't like it and since FxCop normally gives good advice and reasons why i shouldn't do…
Otterprinz
  • 459
  • 3
  • 10
6
votes
2 answers

Prevent .NET code from calling particular methods?

Is there a way to create compile time errors if a certain method is called? As an example, what I'd like to do is prevent code in a certain project from calling System.Configuration.ConfigurationManager.AppSettings(). Is there a way to tag the…
slolife
  • 19,520
  • 20
  • 78
  • 121
6
votes
6 answers

C# Code Analysis dislikes protected static s_Foo (CA1709, CA1707)

I usually add an m_ in front of private fields and an s_ before static members. With a code like protected static readonly Random s_Random = new Random (); I get the following warnings by VS2008's Code Analysis: CA1709: Microsoft.Naming : Correct…
mafu
  • 31,798
  • 42
  • 154
  • 247
6
votes
3 answers

Code Analysis CA1060 Fix

I have the following code in my application: [DllImport("user32.dll")] private static extern int GetWindowLong(IntPtr hwnd, int index); [DllImport("user32.dll")] private static extern int SetWindowLong(IntPtr hwnd, int index, int…
KrisTrip
  • 4,943
  • 12
  • 55
  • 74
6
votes
1 answer

Passing a byte[] around

A third-party generated proxy that we use exposed the BLOB data type as a byte[], and we then expose this value through code generation as follows: public byte[] FileRawData { get { return internalDataRow.FileRawData; } set {…
Daniel Becroft
  • 716
  • 3
  • 19
6
votes
4 answers

How to write Code Analysis (FxCop) rule to prevent a method call

How do I write a code analysis tool for vs2008 to prevent a specific framework call, such as GC.WaitForFullGCComplete() or Application.DoEvents() I tried overriding the VisitMethodCall in my custom rule, but I cannot figure out what the…
Bill
  • 2,381
  • 4
  • 21
  • 24
6
votes
2 answers

Spell checking message strings in .Net projects

I wanted to do a spell check for all the message strings used in my project. How can i do this using fxCop v 1.3.6?? Or do you recommend any other microsoft tool(not third party tool) as our company does not accept that Pls help... Sample code i am…
SSK
  • 783
  • 3
  • 18
  • 42
6
votes
1 answer

Compile-time only Nuget dependency (FxCop)

I am creating a .Net Standard 2.0 Nuget package and I want to perform static code analysis for the build. However, when I add the Microsoft.CodeAnalysis.FxCopAnalyzers package it becomes a runtime dependency, so any projects that reference my Nuget…
scottrudy
  • 1,633
  • 1
  • 14
  • 24
6
votes
1 answer

Analysing FxCop / Code Analysis warning CA1506: AvoidExcessiveClassCoupling

I'm getting Visual Studio Code Analysis warning CA1506 for a C# class. It says, "'FormMain' is coupled with 93 different (non-IComponent) types from 25 different namespaces. Rewrite or refactor this class's methods to decrease its class coupling, or…
RenniePet
  • 11,420
  • 7
  • 80
  • 106
6
votes
2 answers

How to share FxCop rules amongst 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…
Nair
  • 7,438
  • 10
  • 41
  • 69
6
votes
1 answer

Visual Studio 2015 Code Analysis vs FxCopCmd.exe difference

I recently installed Visual Sudio 2015 and was able to run code analysis for the solution with the following command: msbuild.exe MySolution.sln /p:RunCodeAnalysis=true where /p:RunCodeAnalysis=true performs the code analysis. Actually this calls…
Pinte Dani
  • 1,989
  • 3
  • 28
  • 35
6
votes
2 answers

Static analysis dispose warning in test class when object is disposed in test cleanup

I have a lot of test classes like this. [TestClass] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable")] public class TestClass { private IDisposable _disposable; …
r2_118
  • 640
  • 1
  • 9
  • 25