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 - 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...
- IE7 WebControl TreeView line gap in quirks mode. I've been writing a subclass of the MS Webcontrol.TreeView control for one of our Web Applications at work. I figured this would be a fairly easy task, since I only...
- 10 Useful, Often Overlooked HTML Tags. Pop quiz: When would you use the <wbr> tag, and what does it do? Yeah, I had no idea either. In fact, I had never even seen this tag before,...
- 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...
- Lessons in Software Development From the Apollo Moon Missions. Monday was the 40th anniversary of the Apollo 11 lunar landing. The story of the Apollo program is an historic and inspirational one, but it's also relevant to software development....
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......
- Establishing Remodel Cost: Home Remodeling Critical First Step Nothing ruins a fantastic remodel more quickly than exceeding the project budget. Why is this phenomenon so common in residential remodeling? Simple: Many homeowners struggle to establish a detailed budget at the appropriate time in the course of the project. Why is establishing remodel cost one of your most important......
- 2004 internet business ethics standards [affmage source="chitika" results="0"][/affmage] [mage lang="" source="flickr"]2004 internet business ethics standards[/mage] ResumeHow to Make a Resume Because of the volume of resumes employers receive; most of them now use some kind of resume tracking or applicant tracking system. This automates many of the tasks necessary for tracking candidates, and also makes......
