fxcop

Compare two fxcop results

Hi, I'm going to analysis two different versions of the same dll with fxcop. I would like to display only the differences between these two reports. Does anyone know if this is possible ? Thanks for your time. ...

Why is FxCop warning about an overflow (CA2233) in this C# code?

I have the following function to get an int from a high-byte and a low-byte: public static int FromBytes(byte high, byte low) { return high * (byte.MaxValue + 1) + low; } When I analyze the assembly with FxCop, I get the following critical warning: CA2233: OperationsShouldNotOverflow Arithmetic operations should not be don...

The right method of sharing database variables (asp.net)

I have been sharing database variables using the following code: Namespace DataAccessVariables Public Class Vars Public Shared s As String Public Shared con As String = WebConfigurationManager.ConnectionStrings("Dev").ToString() Public Shared c As New SqlConnection(con) Public Shared x As New SqlComma...

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 .NET 4.0. Is there plans to continue to offer FxCop and for it to support .NET 4.0? Where w...

FxCop CA2227 warning and ReadOnlyCollection<T>

In my VS2008 SP1, .NET 3.5 SP1 project, I have different classes that contain different properties. I use C#3.0 auto properties a lot. Some of these properties need to be collections. Since I want to make it simple, I use ReadOnlyCollection<T> for these properties. I don't want to use IEnumerable<T> since I want random access to the el...

Disable AND and OR keywords

In VB.net the ANDALSO and ORELSE keywords should basically always be prefered over the AND and OR keywords. What is the easiest way to disable the AND and OR keywords? I'm thinking FXCop (maybe somebody has already written this rule). Maybe just some setting in VS (we're currently using 2008 and are moving to 2010 end of the summer) I'm...

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 important to keep people safe from doing mistakes. However, if all I'm going to do is throw Ar...

Why do I get CA1806 when I catch exception in C++/CLI?

I've recently upgraded my project from Visual Studio 2008 to Visual Studio 2010. By enabling Code Analysis and compiling in Release, I'm getting warning CA1806: Do not ignore method results. I've managed to reduce the code that produces the warning to this code: .h file: public ref class Foo { public: void Bar(); }; .cpp file: ...

Should I suppress CA2204: Literals should be spelled correctly?

I've recently upgraded my project from Visual Studio 2008 to Visual Studio 2010. By enabling Code Analysis, I'm getting a lot of warnings resulted in rule CA2204: Literals should be spelled correctly. EDIT: Let's say I have a method called GetResult(), and in it I want to throw an exception for some reason. I want the exception to say...

Why do I get CA1811 when I call a private method from a public method in C++/CLI?

I've recently upgraded my project from Visual Studio 2008 to Visual Studio 2010. By enabling Code Analysis and building on Release, I'm getting warning CA1811: Avoid uncalled private code. I've managed to reduce the code to this: .h file: public ref class Foo { public: virtual System::String^ ToString() override; private: st...

Why do I get Code Analysis CA1062 on an out parameter in this code?

I have a very simple code (simplified from the original code - so I know it's not a very clever code) that when I compile in Visual Studio 2010 with Code Analysis gives me warning CA1062: Validate arguments of public methods. public class Foo { protected static void Bar(out int[] x) { x = new int[1]; for (int i =...

Too many false positives when using FxCop.

Dear ladies and sirs. We are using FxCop and it generates too many false positives to our liking. For instance, if a private method is invoked using reflection, then this method is reported as potentially unused - understandable and we suppress this warning explicitly using the SuppressMessage attribute. However, FxCop reports the same ...

Is there a .Net StyleCop rule which warns about lock(this), lock(typeof, lock(<string obj>, etc.?

These 3 types of lock are apparently bad. What other type of locking is bad? Are there Stylecop / FxCop rules that would catch this? If not, then would you please help me with a custom rule implementation? They code for all of them must be similar, right? Thank you. ...

Determining whether a class implements a generic list in a T4 template

I'm writing a T4 template which loads some classes from an assembly, does some analysis of the classes and then generates some code. One particular bit of analysis I need to do is to determine whether the class implements a generic list. I can do this pretty simply in C#, e.g. public class Foo : List<string> { } var t = typeof(Foo); ...

FxCop CA2000 Warning in UserControls

Running FxCop on a WebProject that contains a UserControl will result in a CA2000 Warning (Call System.IDisposable.Dispose on object) for every ServerControl (Label, TextBox,...) in that UserControl. I understand why this would happen. Replacing the 'offending' ServerControls with a PlaceHolder and then adding the Controls in code (Usin...

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 rule right? Or is there a technique like copying the list o something to fix the violation...

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 environment? I get this error message: C:\Program Files (x86)\MSBuild\Microsoft\Visual...

FxCop 1.36 is gone!

Hi, I just wanted to download FxCop 1.36 but I can't find it in the internet. A few days ago FxCop 10 came out for Windows 7 but I need the old Version. The file is gone on the MS server and everybody linked it. Anyone has the old install routine? thanks bembi ...

.NET naming convention for conversion methods: ToType() or AsType() ?

Is there any semantic difference between ToXXXX conversion methods and AsXXXX conversion methods in the .NET framework? Examples of such methods are Object.ToString and Enumerable.AsEnumerable<T>. If no: Are there still recommendations when to name a conversion method AsXXXX and when to name it ToXXXX? If yes: Is there a .NET framewor...

What's behind the FXCop rule CA1061 "Do not hide base class methods"?

Why is the FxCop rule CA1061 a bad idea? The docs state that this rule should not be suppressed. If I have class like so: public class Set<T> { List<T> m_backingList; public bool Contains(T value) { return m_backingList.Contains(value); } } then I add a specific implementation like this: public class C...