fxcop

how to you code a AvoidCallingProblematicMethods exception to be picked up in FxCop?

青春壹個敷衍的年華 提交于 2019-12-24 07:36:32
问题 I am testing FxCop automation and want to validate it is screening and catching certain rules. I want to make a dll that will trigger the AvoidCallingProblematicMethods error in FxCop. I have the following code but it is not triggering the AvoidCallingProblematicMethods rule at all. what am i doing wrong? // use one of the listed unsafe methods to create a problematic method // http://msdn.microsoft.com/en-us/library/bb385973.aspx for list of offending methods GC.Collect(); how can i trip

How do I disable a specific FxCop rule in generated code?

你离开我真会死。 提交于 2019-12-24 03:34:18
问题 I had a problem where I needed to disable a certain rule (in this case CA1819:PropertiesShouldNotReturnArrays) for generated code. If it was my own code, I would have just added a SuppressMessage Attribute to the given function and that's it. Obviously, I can't do that in generated code because it will be lost on the next build. Automatically generated code: [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] [System.SerializableAttribute()] [System.Diagnostics

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

一笑奈何 提交于 2019-12-23 09:36:40
问题 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 done without first validating the operands to prevent overflow. I can't see how this could possibly overflow, so I am just assuming FxCop is being overzealous. Am I missing

Is there a FxCop rule for local used IDisposable's?

China☆狼群 提交于 2019-12-23 09:07:43
问题 ... if I use an IDisposable in a local variable, but do not call Dispose() or use the using() pattern. public void BadMethod() { var fs = new FileStream("file.txt", FileMode.Create); fs.WriteByte(0x55); // no dispose, no using() } Just like the "Types that own disposable fields should be disposable" rule for fields. EDIT: Replaced MemoryStream by FileStream, because MemoryStream just allocates memory and doesn't use (unmanaged) resources, so someone could discuss about a mandatory Dispose()

FXCop Custom Rule does not show up in RuleSet

回眸只為那壹抹淺笑 提交于 2019-12-22 09:48:43
问题 I followed the steps here to create a new custom rule and add it to the ruleset in VSStudio 2013: http://blog.tatham.oddie.com.au/2010/01/06/custom-code-analysis-rules-in-vs2010-and-how-to-make-them-run-in-fxcop-and-vs2008-too/ However, despite all my efforts, the custom rule does not show up in the ruleset file. If I add the rule in the FXCop Editor, it shows up and analyzes the target project correctly. This is the Rule File, which is an embedded resource in the project: <?xml version="1.0"

Custom Rule in FxCop to only apply to methods called by particular type's method

南笙酒味 提交于 2019-12-22 06:57:45
问题 I want to create an FxRule that applies a method, only if the method gets called from a specific class. NOTE: I don't want to just apply a rule to a method of a particular class, i want to be able to handle methods calling other methods calling other methods which do the boxing. I'd like to get FxCop to report problems associated with the method that does the boxing. Below is the code i have so far: using System; using System.Linq; using Microsoft.FxCop.Sdk; using System.Collections.Generic;

Code Analysis CA1060 Fix

北城余情 提交于 2019-12-22 05:11:39
问题 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 newStyle); [DllImport("user32.dll")] private static extern bool SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, int x, int y, int width, int height, uint flags); [DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr wParam

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

删除回忆录丶 提交于 2019-12-21 17:23:37
问题 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. 回答1: The samples (you may need to allow popups in your browser) of John Robbins' Debugging Microsoft .NET Applications book contain sources for such FxCop rules (DoNotLockOnPublicFields, DoNotLockOnThisOrMe, DoNotLockOnTypes, etc.

FxCop 1.36 is gone [closed]

我与影子孤独终老i 提交于 2019-12-21 06:57:33
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . 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? 回答1: I have the 1.36 installer...If you still need it, I could put it

How to enable Code Analysis in Visual Studio 2010 Professional?

佐手、 提交于 2019-12-20 09:13:07
问题 I can see that we can enable code analysis in Visual Studio Team Systems. But i am using Visual Studio 2010 Professional. Do we have any option to enable code analysis in this version or can we integrate any tools like FxCop and StyleCop with this version for validating the code. I am expecting my code should analysied the moment i build my solution. If somebody aware of this, please share me some solution for this. 回答1: You can integrate FxCop via Commandline in the post-build event of the