Microsoft FxCop doesn’t like Microsoft generated code!
The other day I thought it might be nice to “do the right thing” and give my code a run against Microsoft’s FxCop.
I ran it right out of the box - I didn’t bother making my own rules or changing the defaults. I was bored. Anyway, here’s one of the results that actually made be chuckle once I read it carefully:
Warning, Certainty 90, for DoNotInitializeUnnecessarily
{Target : #.ctor() (IntrospectionTargetMember)
Location : <735>> (String)
Resolution : “‘MyDocument.New()’ initializes field ‘MyDocument.disposedValue’
of type ‘Boolean’ to false. Remove this initialization
because it will be done automatically by the runtime.”
Help : (String)
Category : Microsoft.Performance (String)
CheckId : CA1805 (String)
RuleFile : Performance Rules (String)
Info : “Do not make initializations that have already been
done by the runtime.”
Created : 3/6/2009 6:58:21 PM (DateTime)
LastSeen : 3/6/2009 8:36:25 PM (DateTime)
Status : Active (MessageStatus)
Fix Category : NonBreaking (FixCategories)}
The reason for the chuckle was that the code which triggered this violation of the rule was written by the Microsoft IDE! My role in this infraction was really quite simple: I typed “Implements IDisposable” and hit Enter. The IDE was “nice” enough to plugin the rest for me:
[vb language=".net"]
‘ To detect redundant calls
Private disposedValue As Boolean = False
‘ IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
Array.Clear(mDocumentContent, 0, mDocumentContent.Length)
End If
End If
Me.disposedValue = True
End Sub
[/vb]
It’s bad enough that the IDE writes code for me without prompting, but maybe the FxCop team should talk to the IDE team to avoid such embarrassing nuisances (I had dozens of similar warnings to weed through) in the future.
According to the Code Analysis Team, this is the new default for FxCop 1.36.
Here’s how to avoid it:
Using an FxCop project:
- Open your FxCop project in FxCop
- Choose Project -> Options -> Spelling & Analysis
- Check Suppress analysis results against generated code
- Click OK
OR, if you prefer the command-line:
- Pass the /ignoregeneratedcode switch, for example:
FxCopCmd.exe /file:MyAssembly.dll /out:AnalysisResults.xml /ignoregeneratedcode
Related Posts - Are Free Antivirus and Firewall Products Really Any Good? There was a time in my life when I used security and protection suites like Norton and McAfee, but after a while I grew unsatisfied with them. "But Norton and...
- How to Delete Empty Folders - FREE! While performing a disk cleanup recently, I had cause to locate and delete any empty folders under a root folder. I knew there had to be a batch file command...
- Google Chrome: the OS. Google announced last Tuesday that it has its sights on dethroning Microsoft as desktop OS king: "The new operating system, announced late Tuesday night on Google's Web site, will be...
- How To Control Disk Thrash From ccmexec.exe (SMS Agent). Today started like any other day at work. I sat down, logged into my PC and was greeted by the thrashing sound of my hard drive. I've come to realize...
- The 3 Most Important Questions You Should Ask About Each Bug You Find. I stumbled upon (quite literally) an article by Tom Van Vleck titled Three Questions About Each Bug You Find today, and thought I would share it: "The key idea behind...
Related Websites - The Complete Home Improvement Perspective There are lots of people these days that consider themselves good handy people. These people are fond of bragging about their complete home improvement skills and all of the projects they have managed to put together. If you are listening to some of these people, you may just be tempted......
- Generate PDF from HTML with C# in ASP.NET PDF Duo .Net is a converting component for use in ASP.NET (VB, C# etc.) and enables toconvert HTML to PDF. The main class HtmlToPdf provides several methods and properties to enable multi-purpose customization of the resulting PDF. Main functions allow to convert HTML represented as a File, Page from Url......
- Windows Mobile, iPhone, Android - Marketplace Comparison Detailed comparison between Windows Mobile Marketplace, Apple's iPhone AppStore and Android Market from developer point of view. By: Predrag Tomasevic (Click for bigger image) Introduction The article you are about to read is my compilation of thoughts on three currently most popular and talked about mobile platforms, sparked by whole......
- Development and remote installation of Java service for the Android Devices Written by: Igor Darkov, Software Developer of Device Team, Apriorit Inc. In this article I’ve described: How to develop simple Java service for the Android Devices; How to communicate with a service from the other processes and a remote PC; How to install and start the service remotely from the......
- Home Improvement Comes Where to Begin Individuals need to try and do home improvement projects constantly to increase the value of their home. Several folks, but, do not understand that project to tackle initial once they have multiple projects to be done. Selecting which project to try and do initial can be set......
