<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>I may have joined the wrong side : FxCop</title><link>http://msmvps.com/blogs/calinoiu/archive/tags/FxCop/default.aspx</link><description>Tags: FxCop</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>A statistics collection tool for FxCop backlogs</title><link>http://msmvps.com/blogs/calinoiu/archive/2008/02/15/a-statistics-collection-tool-for-fxcop-backlogs.aspx</link><pubDate>Fri, 15 Feb 2008 20:21:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1515394</guid><dc:creator>calinoiu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=1515394</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=1515394</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2008/02/15/a-statistics-collection-tool-for-fxcop-backlogs.aspx#comments</comments><description>&lt;p&gt;For the past week or so, I&amp;#39;ve been performing last-minute documentation tasks at the day job in preparation for the impending maternity leave. If you&amp;#39;ve been reading this blog because of my FxCop posts, then you might be interested in my &lt;a href="http://blog.finrad.com/blog/ncalinoiu/archive/2008/02/15/a-statistics-collection-tool-for-fxcop-backlogs.aspx"&gt;latest post&lt;/a&gt; on the &lt;a href="http://www.finrad.com/blog/"&gt;FinRad blog&lt;/a&gt;, which covers the statistics collection tool that we developed internally to help us track our &lt;a href="http://msmvps.com/blogs/calinoiu/archive/2007/04/22/fxcop-and-the-big-bad-backlog.aspx"&gt;FxCop backlog cleanup efforts&lt;/a&gt;. A copy of the tool is also available on &lt;a href="http://www.codeplex.com/FinRadFxCopStats"&gt;CodePlex&lt;/a&gt; if you would like to try it out for yourself. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1515394" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/FxCop/default.aspx">FxCop</category></item><item><title>Some FxCop rules for VB</title><link>http://msmvps.com/blogs/calinoiu/archive/2007/06/03/some-fxcop-rules-for-vb.aspx</link><pubDate>Sun, 03 Jun 2007 13:34:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:940012</guid><dc:creator>calinoiu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=940012</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=940012</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2007/06/03/some-fxcop-rules-for-vb.aspx#comments</comments><description>&lt;p&gt;We&amp;#39;ve got a rather large VB code base at &lt;a href="http://www.finrad.com/"&gt;FinRad&lt;/a&gt;, at least some of which we would like to migrate to C# in the nearish future. Because of this, we have created several custom rules that are intended to detect issues in VB code that would cause problems when migrating the code to C#. However, while attempting to assign categories for those custom rules, we quickly realized that each of them had merits besides portability of the code base, and that we wanted our assemblies to abide by these rules regardless of whether or not they might eventually be ported to C#. &lt;/p&gt;
&lt;p&gt;I hadn&amp;#39;t been planning on writing a post about these rules for some time to come, but then I saw the announcement last week that &lt;a href="http://www.panopticoncentral.net/archive/2007/05/24/20730.aspx"&gt;Microsoft is using VB to build the Silverlight javascript compiler and VBx&lt;/a&gt;, which seems to have boosted the topic&amp;#39;s prority on my internal TODO list enough that I can&amp;#39;t quite seem to ignore it... &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Rule #1: Interfaces should not contain nested types (Design)&lt;/h3&gt;
&lt;p&gt;By definition, interfaces should not contain any implementation, and a nested type would certainly qualify as implementation. Unfortunately, the VB compiler generates no warnings or errors when any type whatsoever is nested within an interface. For example, the following interface will compile just fine (and FxCop won&amp;#39;t flag it as an &amp;quot;empty&amp;quot; interface either): &lt;/p&gt;&lt;pre class="shaded"&gt;Public Interface ISomething

	Enum Animal
		Cat
		Dog
		Fish
	End Enum

	Class SomeClass
		Public Sub DoSomething()
			Console.WriteLine(&amp;quot;something&amp;quot;)
		End Sub
	End Class

End Interface&lt;/pre&gt;
&lt;p&gt;To make matters worse, the VB compiler will also generate a type within an interface under certain conditions. Consider, for example, the following interface: &lt;/p&gt;&lt;pre class="shaded"&gt;Public Interface ISomethingElse

	Event SomethingDone(ByVal sender As Object, ByVal e As EventArgs)

End Interface&lt;/pre&gt;
&lt;p&gt;When an event is declared using the above syntax, the VB compiler will generate a delegate for the event signature within the same parent type. The resulting compiled assembly actually ends up containing the following interface definition, which includes a nested type: &lt;/p&gt;&lt;pre class="shaded"&gt;Public Interface ISomethingElse
    
    Delegate Sub SomethingDoneEventHandler(ByVal sender As Object, ByVal e As EventArgs)
    
    Event SomethingDone As SomethingDoneEventHandler

End Interface&lt;/pre&gt;&lt;br /&gt;
&lt;h3&gt;Rule #2: Properties should not have arguments (Design)&lt;/h3&gt;
&lt;p&gt;In order to be easily invokable from C#, a property should never have more than one argument, and only indexers (&lt;em&gt;i.e.&lt;/em&gt;: properties named &amp;quot;Item&amp;quot; in VB) should have even one argument. If either of these conventions are ignored, C# code is going to have to use syntax like &lt;code&gt;get_SomeProperty(a, b, c)&lt;/code&gt; to use your properties, which is considerably less readable than some of the alternatives.&amp;nbsp; Do you really want to be forcing your API&amp;#39;s callers to be writing ugly code?&lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Rule #3: Member names should not match type names (Naming)&lt;/h3&gt;
&lt;p&gt;C# will generate compiler error &lt;a href="http://msdn2.microsoft.com/en-us/library/hdhfk2xk(vs.80).aspx"&gt;CS0542&lt;/a&gt; if you try to create a member with the same name as its parent type, but VB won&amp;#39;t complain about this at all. The use of a member with the same name as the type to signify a constructor in C# presumably explains this difference in compiler behaviour. However, there&amp;#39;s an API useability problem here as well since this significance of a member (usually a property) with the same name as its parent class is rarely immediately obvious. For example, imagine a class named &amp;quot;Label&amp;quot; with a property named &amp;quot;Label&amp;quot;. What exactly does &amp;quot;Label.Label&amp;quot; represent? In such a case, either the class or the member probably ought to be renamed to convey more information about its role. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Rule #4: Review call scope forcing (Usage)&lt;/h3&gt;
&lt;p&gt;VB allows for forcing the scope of invocation of a virtual member to the current class via the &lt;code&gt;MyClass&lt;/code&gt; keyword. Both VB and C# allow for forcing the scope of invocation of a virtual member to the base class (via &lt;code&gt;MyBase&lt;/code&gt; and &lt;code&gt;base&lt;/code&gt;, respectively). Since call scope forcing isn&amp;#39;t really a VB-specific capability, this isn&amp;#39;t really a VB-specific rule. However, eliminating &lt;code&gt;MyClass&lt;/code&gt; use was what provoked its development at FinRad, so I&amp;#39;m including it here anyway. &lt;/p&gt;
&lt;p&gt;In case you&amp;#39;re wondering why call scope forcing should be reviewed, consider why a member would be declared as virtual in the first place: it&amp;#39;s meant to be overrideable. If a subclass has overridden a virtual method, why should a base class be deliberately avoiding invoking that override? Obviously, there are cases where this behaviour is desirable, which is why this is a &amp;quot;review&amp;quot; rule rather than a &amp;quot;do not&amp;quot; rule, but there are also plenty of cases where scope forcing is likely to be used inappropriately, particularly when developers aren&amp;#39;t aware of the consequences. &lt;/p&gt;
&lt;p&gt;If you want to implement this rule, there are a few things to watch out for: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Within the implementation of an overriding, overloading, or hiding member, it is quite common to invoke the base class implementation explicitly. In order to avoid undesirable noise in the rule analysis results, these cases should not be flagged as problems by the rule.&lt;/li&gt;
&lt;li&gt;Because of VB interface member implementation renaming, the name of an overload will not necessarily be the same as the name of the member it is overloading.&lt;/li&gt;
&lt;li&gt;The C# compiler will force a non-virtual call when invoking a non-virtual base class member even if your code uses &lt;code&gt;this&lt;/code&gt; rather than &lt;code&gt;base&lt;/code&gt; to scope the call. The VB compiler will retain the virtual call.&lt;/li&gt;
&lt;li&gt;FxCop 1.35 and Visual Studio 2005 Static Analysis both have problems detecting whether a property is overriding and/or hiding, although the exact behaviour differs between the two engines, as well as between .NET 1.1. and 2.0 assemblies for FxCop 1.35. For more details on this issue (which appears to have been resolved in Orcas), see &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=270446"&gt;this bug report&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=940012" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/FxCop/default.aspx">FxCop</category></item><item><title>FxCop backlog tools: FxCop</title><link>http://msmvps.com/blogs/calinoiu/archive/2007/06/02/fxcop-backlog-tools-fxcop.aspx</link><pubDate>Sat, 02 Jun 2007 13:07:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:938708</guid><dc:creator>calinoiu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=938708</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=938708</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2007/06/02/fxcop-backlog-tools-fxcop.aspx#comments</comments><description>&lt;p&gt;If you&amp;#39;re considering tackling &lt;a href="http://msmvps.com/blogs/calinoiu/archive/2007/04/22/fxcop-and-the-big-bad-backlog.aspx"&gt;an FxCop backlog&lt;/a&gt;, you&amp;#39;re going to need a few tools. Obviously, the most important of these is FxCop itself, but that still leaves you with a potential choice to make between stand-alone FxCop and Visual Studio Static Analysis. If your target code base is built against .NET 1.1 or if you&amp;#39;re not willing/able to shell out for Team Edition for Software Developers or Team Suite, the decision is pretty trivial. However, what if all your developers already have Visual Studio 2005 editions that include static analysis? You&amp;#39;ve paid for it, so your first instinct will probably be to use it. Unfortunately, it&amp;#39;s probably not the best tool for this particular job. &lt;/p&gt;
&lt;p&gt;While VStudio Static Analysis is great for dealing with a small volume of problems that should be addressed immediately, it kind of sucks the big wazoo with respect to handling the much larger volume of violations that one needs to deal with while tackling a backlog. This is partly a UI issue, and it shouldn&amp;#39;t come as much as a surprise given that the backlog scenario probably wasn&amp;#39;t exactly a major priority during the development of the VStudio integration piece. However, there are also some issues that go beyond the limited capabilities of the Visual Studio Error List window, and it&amp;#39;s important to be aware of these as you make your tooling decisions. &lt;/p&gt;
&lt;p&gt;In order to help understand why the stand-alone tool will likely be a better choice, let&amp;#39;s take a closer look at some of the tasks in the backlog winnowing process... &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Fix this &lt;/h3&gt;
&lt;p&gt;You&amp;#39;ve decided to activate a given rule. Your code base has 400 existing violations of the rule, and you want your team to start fixing those right away. However, you certainly don&amp;#39;t want to have to specifically assign each and every fix to a given developer. How do you create a &amp;quot;pool&amp;quot; of violations from which developers can draw? &lt;/p&gt;
&lt;p&gt;If you&amp;#39;re using Static Analysis and you also happen to be using Team Foundation Server, you might want create work items for the violations, then let developers assign the work items to themselves before starting to work on the fixes. However, from the VStudio Error List, you&amp;#39;re going to able to generate work items in only one of two ways: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Select all the violations, then generate a single work item, or&lt;/li&gt;
&lt;li&gt;Generate a work item for each violation individually.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Generating the individual work items would be ridiculously time consuming and tedious, so a single work item would usually be the only practical choice. However, in order to ensure that the more than one developer isn&amp;#39;t working on any given violation at the same time, there&amp;#39;s still going to have to be some manual work in terms of copying and editing work items before a developer will even start fixing a violation. Unfortunately, this procedural overhead doesn&amp;#39;t really have much added value besides preventing overlapping work, and the additional effort may end up accounting for a very large proportion of the time spent on any given fix. Wouldn&amp;#39;t you rather use that time for fixing other violations instead? (Of course, you could create a tool that automatically creates individual work items for you based on an FxCop output report, but that&amp;#39;s again time that might be better spent doing other things.) &lt;/p&gt;
&lt;p&gt;Another problem with adding backlog work items to TFS from VStudio Static Analysis results is that they&amp;#39;re going to end up in the same TFS project as all your &amp;quot;real&amp;quot; work items for the same code base. Assuming your Static Analysis backlog is non-trivial, these backlog work items will start to swamp out your other feature and bug fix work items pretty quickly. Sure, you can isolate them in a category of their own, but sooner or later someone is going to include those beasties in a report where they shouldn&amp;#39;t belong, and your stats are going to be skewed halway to heck. &lt;/p&gt;
&lt;p&gt;OK, so if those are problems with using Static Analysis for violation reservation, what can the cheapskate&amp;#39;s standalone edition do better? For starters, we can mark all the violations for fixing in one step without requiring later splitting. After activating a new rule and executing an analysis, simply select all the newly active violations of the rule and exclude them with a &amp;quot;TODO&amp;quot; note. If you&amp;#39;re feeling fancy, you can even add a priority level (&lt;i&gt;e.g.&lt;/i&gt;: &amp;quot;TODO 1&amp;quot; or &amp;quot;TODO 2&amp;quot;). After excluding the pre-existing violations, simply check the FxCop project into source control, and all the developers on your team can instantly access the items. &lt;/p&gt;
&lt;p&gt;Under the &amp;quot;TODO&amp;quot; exclusion scheme, it&amp;#39;s equally easy for any given developer to grab himself a chunk of new backlog work. He simply selects a bunch of violations from those that still have &amp;quot;TODO&amp;quot; notes, adds a new note (in one step) to claim all of them, then checks the modified FxCop project back into source control. What&amp;#39;s this new note that gets added for the claiming? At &lt;a href="http://www.finrad.com/"&gt;FinRad&lt;/a&gt;, we simply add our initials to the note. For example, I claim violations by adding the note &amp;quot;TODO - NC&amp;quot; to an unclaimed TODO exclusion. If you&amp;#39;ve got a bigger team, you might need to identify developers by somewhat longer strings than their initials, but the underlying technique should still work. &lt;/p&gt;
&lt;p&gt;Using stand-alone FxCop and TODO exclusions, I can both create and reserve violation &amp;quot;work items&amp;quot; in seconds, so I can spend more time on actually fixing violations rather than on managing the workload itself. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Don&amp;#39;t break that&lt;/h3&gt;
&lt;p&gt;Identifying the current workload is only part of managing the violation backlog. Another important part is ensuring that the backlog violations that have not yet been fixed don&amp;#39;t break your builds (assuming, of course, that you&amp;#39;re using automated builds and that you&amp;#39;ve set FxCop rule violations to break those builds). If you&amp;#39;re using VStudio Static Analysis, you&amp;#39;ve got two basic options for doing this: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Set the rule to not break the build until after all the backlog violations are fixed or&lt;/li&gt;
&lt;li&gt;Use SuppressMessageAttribute to exclude the pre-existing violations.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;If you don&amp;#39;t allow violations of the newly activated rule to break the build, you won&amp;#39;t start detecting new violations of the rule until after you&amp;#39;ve cleaned up the entire backlog, and that&amp;#39;s not pretty. On the other hand, if you add a SuppressMessageAttribute to any given pre-existing violation, that violation will no longer show up in the Error List, so it&amp;#39;s going to start being difficult for your team members to find and fix the problem. &lt;/p&gt;
&lt;p&gt;Another problem with the SuppressMessageAttribute exclusions approach is that VStudio Static Analysis doesn&amp;#39;t let you know when you don&amp;#39;t need a suppression anymore.&lt;sup&gt;1&lt;/sup&gt; This means that if you fix the original violation but forget to remove the attribute, you could later create another violation of the same rule in the same code element, and you&amp;#39;ll never notice it because the old placeholder exclusion will hide the new problem. That&amp;#39;s a nasty enough problem even when you have a small number of &amp;quot;real&amp;quot; exclusions, but it&amp;#39;s asking for big trouble when you consider the very large number of suppressions that you would need to create for your backlog violations. &lt;/p&gt;
&lt;p&gt;This is another problem for which a much cleaner, simpler solution is possible when using the FxCop stand-alone UI. In fact, we&amp;#39;ve already covered the approach above. Since we create a &amp;quot;TODO&amp;quot; exclusion for every violation in the immediate backlog, we can keep the rule activated and build-breaking while still readily identifying the backlog violations. The stand-alone UI also allows us to detect exclusions that are no longer needed, so we can remove the unecessary exclusions in batches even if individual developers forget to remove them when fixing a violation. &lt;/p&gt;
&lt;p&gt;On a bit of a side note, if you happen to be running a backlog cleanup of a .NET 2.0 application, you will probably want to store only your TODO exclusions in the FxCop project file. If you happen to resolve a violation by creating a &amp;quot;real&amp;quot; exclusion, that exclusion should probably be created with SuppressMessageAttribute rather than in the FxCop project file. After all, one of these days, you&amp;#39;ll actually finish tackling the backlog, and you may want to switch over to using VStudio Static Analysis for finding and addressing the piddly few rule violations you&amp;#39;ll be generating in your day-to-day work. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Sorting, filtering, and other fancy-pants advanced techniques&lt;/h3&gt;
&lt;p&gt;So let&amp;#39;s say you&amp;#39;re a developer who is ready to give an hour or so to fixing some of the backlog problems. How to you select which ones to work on? If you simply grab a random assortment, you&amp;#39;ll probably end up working on violations of a variety of different rules that are widely separated with respect to location in the source code. You&amp;#39;ll very likely end up wasting time on context switching that could have been put to much better use actually fixing violations. &lt;/p&gt;
&lt;p&gt;As a more concrete example, let&amp;#39;s say you decide that you have time to fix about 30 violations of the &lt;a href="http://msdn2.microsoft.com/en-us/library/ms182278(vs.80).aspx"&gt;Performance.RemoveUnusedLocals&lt;/a&gt; rule. Trivial as these might seem, chances are that you&amp;#39;ll probably find that somewhere between 10% and 20% of the violations actually require some decisions and maybe even a bit of code spelunking. This is why you won&amp;#39;t try tackling 3 or 4 violations per minute, but it also has another consequence. If you&amp;#39;re going to be encountering &amp;quot;weird&amp;quot; violations, wouldn&amp;#39;t it be nice if they&amp;#39;re mostly of the same style? One way of trying to increase the probably of this would be to draw the violations from a smallish area of the code base, where you&amp;#39;ll at least stand a reasonable chance of encountering mostly code authored by a single developer. &lt;/p&gt;
&lt;p&gt;While selecting violations using the above pattern is certainly possible from the VStudio Error List, it&amp;#39;s not terribly convenient, and it&amp;#39;s certainly not something that most of your developers are likely to enjoy doing several times a week. Developer patience with the selection process is likely to fray even faster if you&amp;#39;re using TFS to store the backlog work items. To make things worse, you&amp;#39;ll again be wasting time that could be better spent on actually fixing violations. &lt;/p&gt;
&lt;p&gt;On the other hand, making the same issue selection in the stand-alone FxCop UI is trivial. First, I select the Performance.RemoveUnusedLocals rule in the rule treeview to hide violations of any other rule. Then I sort the &amp;quot;Excluded In Project&amp;quot; list by the item column. Since I can see availability of items in the &amp;quot;Last Note&amp;quot; column, all I have to do is select a bunch of violations that are clustered close together by item path in order to increase the chances of similar types of weirdness in the problems that I&amp;#39;m going to address.&lt;sup&gt;2&lt;/sup&gt; &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;But I don&amp;#39;t like the extra step involved in running FxCop...&lt;/h3&gt;
&lt;p&gt;Let&amp;#39;s step back a moment and look at the usual reason for preferring VStudio Static Analysis: it runs seemlessly as part of the build process. Even ignoring the backlog problem, there&amp;#39;s another nasty gotcha here: duration of a static analysis run. It takes over 3 minutes to analyze the assemblies in the product on which I work day-to-day. Given this, I&amp;#39;m certainly not going to run an analysis as part of my usual debug builds, whether it&amp;#39;s via the integrated Static Analysis tool or by launching FxCop via a post-build event. If I really want the analysis to be associated with a build, I&amp;#39;m going to have to create an alternate build configuration at the very least. &lt;/p&gt;
&lt;p&gt;This means that, even if I&amp;#39;m targeting the integrated tool, I&amp;#39;m still going to be launching analyses via a conscious, at least partially manual step. With one little extra step (clicking the &amp;quot;Analyze&amp;quot; button within the FxCop UI), I can run the analysis in the richer, otherwise more convenient stand-alone UI instead. To make this rapid launch possible, I simply add my FxCop project file to my solution as a solution item, then configure Visual Studio to open FxCop files using FxCop.exe. Once this initial setup is done, all I need to do to run my FxCop analysis is open the FxCop project from within Visual Studio then click the &amp;quot;Analyze&amp;quot; button once the FxCop UI has opened (to watch a 700K demo video, &lt;a href="http://bordecal.mvps.org/Nicole/media/FxCopUIDemo/Default.htm"&gt;click here&lt;/a&gt;). That&amp;#39;s amply convenient for me, although I guess your mileage may vary (but only if you&amp;#39;re a complete nut &amp;lt;gdr&amp;gt;). &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;But that Static Analysis thingy cost me 5000$ (per seat) !!!&lt;/h3&gt;
&lt;p&gt;If you&amp;#39;ve bought one of the Team System editions that includes static analysis, I very much hope that you&amp;#39;re taking full advantage of it for your new development work. I also hope that static analysis isn&amp;#39;t the only &amp;quot;extra&amp;quot; feature that you&amp;#39;re using, or perhaps you did spend rather a lot for one feature. ;) Either way, the fact that you happen to have the integrated static analysis tool available to you shouldn&amp;#39;t be an important factor in making a decision regarding which FxCop tool to use for your backlog cleanup project. &lt;/p&gt;
&lt;p&gt;On the other hand, the integrated tool ships with some rules that are not available in the free version of FxCop, and you might be swayed toward using that tool in order to take advantage of the additional rules, particularly given that FxCop 1.35 and Visual Studio 2005 Static Analysis cannot consume each other&amp;#39;s rules. However, what you may not know is that FxCop 1.35 also shipped with some rules that aren&amp;#39;t present in the integrated static analysis rule set&lt;sup&gt;3&lt;/sup&gt;. The following table lists the rule set differences: &lt;/p&gt;
&lt;table class="standardPostTable" cellspacing="0" cellpadding="4" class="standardPostTable"&gt;

&lt;tr&gt;
&lt;th class="" align="left"&gt;Category&lt;/th&gt;
&lt;th class="" align="left"&gt;FxCop 1.35&lt;/th&gt;
&lt;th class="" align="left"&gt;Visual Studio 2005&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;Design&lt;/td&gt;
&lt;td class=""&gt;ExceptionsShouldBePublic&lt;/td&gt;
&lt;td class=""&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;Maintainability&lt;/td&gt;
&lt;td class=""&gt;&amp;nbsp;&lt;/td&gt;
&lt;td class=""&gt;AvoidExcessiveComplexity&lt;br /&gt;AvoidExcessiveInheritance&lt;br /&gt;VariableNamesShouldNotMatchFieldNames&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;Naming&lt;/td&gt;
&lt;td class=""&gt;CompoundWordsShouldBeCasedCorrectly&lt;br /&gt;FlagsEnumsShouldHavePluralNames&lt;br /&gt;IdentifiersShouldBeSpelledCorrectly&lt;br /&gt;OnlyFlagsEnumsShouldHavePluralNames&lt;br /&gt;ResourceStringCompoundWordsShouldBeCasedCorrectly&lt;br /&gt;ResourceStringsShouldBeSpelledCorrectly&lt;/td&gt;
&lt;td class=""&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;Performance&lt;/td&gt;
&lt;td class=""&gt;RemoveEmptyFinalizers&lt;/td&gt;
&lt;td class=""&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;Reliability&lt;/td&gt;
&lt;td class=""&gt;&amp;nbsp;&lt;/td&gt;
&lt;td class=""&gt;DisposeObjectsBeforeLosingScope&lt;br /&gt;DoNotLockOnObjectsWithWeakIdentity&lt;br /&gt;DoNotTreatFibersAsThreads&lt;br /&gt;RemoveCallsToGCKeepAlive&lt;br /&gt;UseSafeHandleToEncapsulateNativeResources&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;Security&lt;/td&gt;
&lt;td class=""&gt;CatchNonClsCompliantExceptionsInGeneralHandlers&lt;br /&gt;SecurityTransparentAssembliesShouldNotContainSecurityCriticalCode&lt;br /&gt;SecurityTransparentCodeShouldNotAssert&lt;br /&gt;SecurityTransparentCodeShouldNotReferenceNonpublicSecurityCriticalCode&lt;/td&gt;
&lt;td class=""&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;Usage&lt;/td&gt;
&lt;td class=""&gt;AttributeStringLiteralsShouldParseCorrectly&lt;br /&gt;LiteralsShouldBeSpelledCorrectly&lt;br /&gt;TestForNaNCorrectly&lt;/td&gt;
&lt;td class=""&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;If you&amp;#39;re seeking to maximize your rule coverage, jumping on static analysis because it supposedly contains more rules isn&amp;#39;t exactly looking like an optimal approach... If you want to cover the combined rule set offered by the two tools, I&amp;#39;d recommend using FxCop 1.35 for your backlog cleanup until you&amp;#39;ve exhausted all of its rules. Once that&amp;#39;s done, you would potentially be faced with a decision of switching over to the integrated tool for the remaining rules or coding custom rules for FxCop 1.35 that check for the same problems as the additional rules shipped with Visual Studio. &lt;/p&gt;
&lt;p&gt;Then again, is that really a decision you&amp;#39;re likely to end up facing? Assuming you start a backlog cleanup now, when do you think you&amp;#39;re likely to be almost done? Unless your backlog is trivial, chances are excellent that both Orcas and FxCop vNext will have shipped by the time you&amp;#39;re even half way done. Personally, I&amp;#39;m hoping that Orcas static analysis and FxCop vNext will be able to consume each other&amp;#39;s rules, thereby making it possible to use the richer UI when addressing a backlog of the Visual Studio rules, as well as easing some of the pain around custom rule authoring. There&amp;#39;s no technical reason why they shouldn&amp;#39;t be able to consume the same rules, but that doesn&amp;#39;t mean that a difference couldn&amp;#39;t be introduced explicitly in order to prevent using the expensive rules from the free tool. I&amp;#39;m keeping my fingers crossed that this won&amp;#39;t happen, although I won&amp;#39;t start counting any chickens until Orcas and FxCop vNext have both RTMed... &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;
&lt;hr /&gt;

&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt;If you wish VStudio Static Analysis and/or FxCopCmd.exe would let you know when you&amp;#39;ve got unecessary suppressions, vote &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=277253"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;sup&gt;2&lt;/sup&gt;If FxCop wouldn&amp;#39;t &amp;quot;lose&amp;quot; the rule selection when switching between the rules and targets treeviews, it would be possible to make an even more convenient selection by &amp;quot;climbing&amp;quot; the target treeview from the target associated with any given violations. Unfortunately, the rule selection is lost when switching to the other treeview tab in FxCop 1.35. I&amp;#39;m keeping my fingers crossed that this won&amp;#39;t be the case in the vNext UI, but there seems little point in creating a bug report until I&amp;#39;ve actually tried the beastie.&amp;nbsp; I&amp;#39;m also hoping that the vNext UI will allowing filtering by column values within the violation lists, which would also make working with large backlog lists more convenient, but I won&amp;#39;t be holding my breath for that change.&lt;/p&gt;
&lt;p&gt;&lt;sup&gt;3&lt;/sup&gt;In case you&amp;#39;re not already aware of this, the Visual Studio rule set is supposed to be a superset of the stand-alone FxCop rule set. FxCop 1.35 only contains rules that aren&amp;#39;t present in Visual Studio 2005 because of time constraints during the preparation of Visual Studio 2005. (Sorry, but the best reference I seem to be able to find regarding this at the moment is &lt;a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=706148&amp;amp;SiteID=1#719554"&gt;a post on the FxCop forum&lt;/a&gt;.) The extra FxCop 1.35 rules are present in Orcas, with the exception of &lt;a href="http://msdn2.microsoft.com/en-us/library/bb264488(VS.80).aspx"&gt;Usage.LiteralsShouldBeSpelledCorrectly&lt;/a&gt;, which is a &lt;a href="http://msmvps.com/blogs/calinoiu/archive/2007/04/28/control-flow-engine-200-2007-rip.aspx"&gt;control flow rule&lt;/a&gt;. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=938708" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/FxCop/default.aspx">FxCop</category></item><item><title>FxCop backlog themes: Disposition and finalization</title><link>http://msmvps.com/blogs/calinoiu/archive/2007/05/16/fxcop-backlog-themes-disposition-and-finalization.aspx</link><pubDate>Wed, 16 May 2007 19:44:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:907773</guid><dc:creator>calinoiu</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=907773</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=907773</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2007/05/16/fxcop-backlog-themes-disposition-and-finalization.aspx#comments</comments><description>&lt;p&gt;I skipped ahead a while back with my &lt;a href="http://msmvps.com/blogs/calinoiu/archive/2007/05/05/fxcop-backlog-themes-exceptions.aspx"&gt;post on the exceptions theme&lt;/a&gt;, and it&amp;#39;s time to get back on track with stuff that would usually precede that rather involved topic during an FxCop backlog cleanup project. &lt;/p&gt;
&lt;p&gt;The good news with the disposition and finalization topic is that its scope is quite a bit narrower than the exceptions topic. The bad news is that you&amp;#39;ll probably see almost as many preconceptions regarding how it works, particularly if you have quite a few developers who are accustomed to deterministic finalization. As with the exceptions topic, it&amp;#39;s probably a pretty good idea to start the topic from scratch, making the assumption that most of the developers on your team will get at least something from coverage of even the fundamentals of the subject matter. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Resources&lt;/h3&gt;
&lt;p&gt;This time around, Chris Brumme&amp;#39;s &lt;a href="http://blogs.msdn.com/cbrumme/archive/2004/02/20/77460.aspx"&gt;post on finalization&lt;/a&gt; is absolutely required reading, at least for the topic trainer. If you don&amp;#39;t understand at least 90% of that article, you probably don&amp;#39;t know enough about finalization to be teaching the topic. &lt;/p&gt;
&lt;p&gt;You&amp;#39;ll also need some resources that are more on the &amp;quot;how to&amp;quot; side of things. The MSDN articles &lt;a href="http://msdn2.microsoft.com/en-us/library/b1yfkh5e(VS.80).aspx"&gt;Implementing Finalize and Dispose to Clean Up Unmanaged Resources&lt;/a&gt; and &lt;a href="http://msdn2.microsoft.com/en-us/library/fs2xkftw(VS.80).aspx"&gt;Implementing a Dispose Method&lt;/a&gt; to provide a reasonable starting point around guidelines for finalization and disposition. By the time you complete your training on finalization and disposition, all the developers on your team should be able to read and understand these articles. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Some gotchas&lt;/h3&gt;
&lt;p&gt;By and large, the documentation available is pretty clear, and the recommended practices are relatively unambiguous. However, we did run into a few picky detail issues while tackling the disposition and finalization theme at &lt;a href="http://www.finrad.com/"&gt;FinRad&lt;/a&gt;: &lt;/p&gt;
&lt;ol&gt;
&lt;li class="spaced"&gt;&lt;i&gt;In a disposable class that contains a collection of disposable items, how does one deal with exceptions that might be thrown during the disposition of any individual item?&lt;/i&gt;&lt;br /&gt;The issue here is that one wants to continue disposing of any remaining items even if an exception is thrown while disposing of any given item. However, one still wants to throw an exception out of the parent class &lt;code&gt;Dispose&lt;/code&gt; method. The question here is exactly what should one end up throwing? One answer is to store any exceptions into some custom exception that contains an exception collection, then throw the resulting beastie at the end of the process. Unfortunately, there are several problems with this approach, not least of which is that the original &lt;code&gt;Dispose&lt;/code&gt; method caller isn&amp;#39;t likely to be want to iterate over the exception collection trying to decide what to do about each and every one of the member exceptions. &lt;br /&gt;&lt;br /&gt;What we ended up deciding to do instead was to treat disposition of each individual collection item as if it we were disposing a field on the parent class. In other words, we wanted to expose the same exception scenario that would be seen if we were able to code the parent &lt;code&gt;Dispose&lt;/code&gt; method like this: &lt;pre class="shaded"&gt;try
{
	this._someDisposableField.Dispose();
}
finally
{
	try
	{
		this._someOtherDisposableField.Dispose();
	}
	finally
	{
		try
		{
			this._collectionOfDisposables[0].Dispose();
		}
		finally
		{
			try
			{
				this._collectionOfDisposables[1].Dispose();
			}
			finally
			{
				...
			}
		}
	}
}&lt;/pre&gt;If one were able to do this, the only exception the caller of the parent class &lt;code&gt;Dispose&lt;/code&gt; method would see is the last exception thrown in any of the individual try blocks. This is quite easy to simulate even while disposing in a loop. &lt;i&gt;e.g.&lt;/i&gt;: &lt;pre class="shaded"&gt;try
{
	this._someDisposableField.Dispose();
}
finally
{
	try
	{
		this._someOtherDisposableField.Dispose();
	}
	finally
	{
		try
		{
			Exception lastException = null;
			foreach (IDisposable item in this._collectionOfDisposables)
			{
				try
				{
					item.Dispose();
				}
				catch (Exception ex)
				{
					lastException = ex;
				}
			}

			if (lastException != null) throw lastException;
		}
		finally
		{
			GC.SuppressFinalize(this);
		}
	}
}&lt;/pre&gt;Is this ideal? Obviously not, but I happen to believe that it presents less problems than any of the alternatives. If you think you have a better approach, I&amp;#39;d love to hear about it. &lt;/li&gt;
&lt;li class="spaced"&gt;&lt;i&gt;What exactly is an unmanaged resource?&lt;/i&gt;&lt;br /&gt;The basic rules for implementing disposition and finalization are the following: 
&lt;ul&gt;
&lt;li&gt;If a class has a disposable field, it should disposed from the &lt;code&gt;Dispose&lt;/code&gt; method of the parent class.&lt;/li&gt;
&lt;li&gt;If a class has a field that represents an unmanaged resource, this should be released from both the &lt;code&gt;Dispose&lt;/code&gt; method and the finalizer of the parent class.&lt;/li&gt;&lt;/ul&gt;The first rule is pretty unambiguous, but what exactly qualifies as an &amp;quot;unmanaged resource&amp;quot; that should be released both on disposition and finalization of the parent class? Most of the articles on disposition and finalization make some airy-fairy mention of things like database connections and file handles, but does that mean a &lt;code&gt;SqlConnection&lt;/code&gt; should be disposed in the parent class finalizer? The simple answer is &amp;quot;no&amp;quot;. The barely more complicated answer is pretty much the only things you should be cleaning up during finalization are &lt;code&gt;IntPtr&lt;/code&gt; fields. If you&amp;#39;ve gone beyond &lt;code&gt;IntPtr&lt;/code&gt; to start using &lt;code&gt;SafeHandle&lt;/code&gt; in .NET 2.0, you don&amp;#39;t even need worry about those since the unmanaged handle is already wrapped in a disposable, finalizable managed object.&lt;/li&gt;
&lt;li class="spaced"&gt;&lt;i&gt;There&amp;#39;s no framework design guideline with respect to interface inheritance from IDisposable, but there probably ought to be.&lt;/i&gt;&lt;br /&gt;Interfaces that are likely to be implemented by types that will need to be disposable should themselves be disposable. This is because you don&amp;#39;t want to end up having to write code that looks like this: &lt;pre class="shaded"&gt;IShouldBeDisposableButIsNot thingy = Factory.CreateThingammy();
try
{
	//...
}
finally
{
	IDisposable disposableThingy = thingy as IDisposable;
	if (disposableThingy != null) disposableThingy.Dispose();
}&lt;/pre&gt;Instead, you want to be able to simply write code like this: &lt;pre class="shaded"&gt;using (IShouldBeDisposableAndIs thingy = Factory.CreateThingammy())
{
	//...
}&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;
&lt;h3&gt;The built-in rules&lt;/h3&gt;
&lt;p&gt;Here are the built-in rules that you&amp;#39;ll want to start activating during the disposition and finalization theme: &lt;/p&gt;
&lt;table class="standardPostTable" cellspacing="0" cellpadding="4" class="standardPostTable"&gt;






&lt;tr&gt;
&lt;th class=""&gt;Category&lt;/th&gt;
&lt;th class=""&gt;Rule&lt;/th&gt;
&lt;th class=""&gt;In FxCop 1.35?&lt;/th&gt;
&lt;th class=""&gt;In VStudio 2005?&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="" rowspan="3"&gt;Design&lt;/td&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms244737(VS.80).aspx"&gt;ImplementIDisposableCorrectly&lt;/a&gt;&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms182172(VS.80).aspx"&gt;TypesThatOwnDisposableFieldsShouldBeDisposable&lt;/a&gt;&amp;nbsp;&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms182173(VS.80).aspx"&gt;TypesThatOwnNativeResourcesShouldBeDisposable&lt;/a&gt;&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;
&lt;td class=""&gt;x&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="" rowspan="2"&gt;Performance&amp;nbsp;&lt;/td&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms182269(VS.80).aspx"&gt;DisposeMethodsShouldCallSuppressFinalize&lt;/a&gt;&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/bb264476(vs.80).aspx"&gt;RemoveEmptyFinalizers&lt;/a&gt;&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;
&lt;td class=""&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;Reliability&amp;nbsp;&lt;/td&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms182289(VS.80).aspx"&gt;DisposeObjectsBeforeLosingScope&lt;/a&gt;&lt;/td&gt;
&lt;td class=""&gt;&amp;nbsp;&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="" rowspan="6"&gt;&amp;nbsp;Usage&lt;/td&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms182328(VS.80).aspx"&gt;DisposableFieldsShouldBeDisposed&lt;/a&gt;&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms182329(VS.80).aspx"&gt;DisposableTypesShouldDeclareFinalizer&lt;/a&gt;&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms182330(VS.80).aspx"&gt;DisposeMethodsShouldCallBaseClassDispose&lt;/a&gt;&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms182334(VS.80).aspx"&gt;DoNotDisposeObjectsMultipleTimes&lt;/a&gt;&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;
&lt;td class=""&gt;x&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms182340(VS.80).aspx"&gt;FinalizersShouldBeProtected&lt;/a&gt;&amp;nbsp;&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms182341(VS.80).aspx"&gt;FinalizersShouldCallBaseClassFinalizer&lt;/a&gt;&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;
&lt;td class=""&gt;x&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;
&lt;h3&gt;Some custom rule ideas&lt;/h3&gt;
&lt;p&gt;We haven&amp;#39;t created any custom rules yet around finalization and disposition at FinRad, but there are at least a couple that I would like to implement eventually: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;IDisposable.Dispose should be called from within a finally block (and the only other code in the finally block should be a cast to IDisposable)&lt;/li&gt;
&lt;li&gt;An interface with at least one disposable implementation should itself be disposable&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;That last one is bound to be interesting to try to author, but I&amp;#39;ve got loads of time to figure out how to implement it since there are quite a few more important rules to tackle first... &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=907773" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/FxCop/default.aspx">FxCop</category></item><item><title>FxCop is case-sensitive. VB is annoying.</title><link>http://msmvps.com/blogs/calinoiu/archive/2007/05/07/fxcop-is-case-sensitive-vb-is-annoying.aspx</link><pubDate>Tue, 08 May 2007 03:30:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:894175</guid><dc:creator>calinoiu</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=894175</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=894175</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2007/05/07/fxcop-is-case-sensitive-vb-is-annoying.aspx#comments</comments><description>&lt;p&gt;With profound apologies to VB lovers, there are a few features of the VB compiler that occasionally make me want to start drinking at a very early hour of the day. Perhaps the most troublesome of these is its failure to start screaming bloody murder upon detection of namespaces that differ only by case, even while compiling an assembly that is marked as CLS-compliant. VB 2005 is at least kind enough to conserve the casing from the source code. However, VB 2003 seems to more or less randomly pick one case version and apply it throughout an assembly, and that leads to all sorts of fun and games. &lt;/p&gt;
&lt;p&gt;If you&amp;#39;ve developed mixed VB and C# solutions, chances are pretty good that this isn&amp;#39;t exactly news to you since C# tends to get mighty unhappy the resulting changes in namespace casing. However, you might be blissfully unaware that FxCop is also case-sensitive, and that has its own special set of consequences... &lt;/p&gt;
&lt;p&gt;At &lt;a href="http://www.finrad.com/"&gt;FinRad&lt;/a&gt;, we&amp;#39;re still supporting applications that run against .NET 1.1 (and will be for at least a couple more years), and a very large part of that code base is written in VB 2003. Given that this is .NET 1.1 code, we&amp;#39;re using the stand-alone version of FxCop for static analysis, and exclusions are stored in the FxCop project file, not as &lt;a href="http://msdn2.microsoft.com/en-us/library/system.diagnostics.codeanalysis.suppressmessageattribute.aspx"&gt;SuppressMessageAttribute&lt;/a&gt; annotations in the source code. &lt;/p&gt;
&lt;p&gt;Given that this also happens to be the same code base covered by the bulk of our &lt;a href="http://msmvps.com/blogs/calinoiu/archive/2007/04/22/fxcop-and-the-big-bad-backlog.aspx"&gt;backlog cleanup efforts&lt;/a&gt;, the FxCop project files contain an unusually large number of exclusions. (I&amp;#39;ll write about the reasons for this soon. For now, just trust me: lots more violation exclusions than you might normally expect.) Every now and then, we would end up with a situation where a sizeable chunk of our exclusions would suspiciously disappear, and all the violations they covered would auto-magically become active again. Needless to say, this was terribly annoying, but we chalked it up to gremlins, manually re-created the exclusions, and forged bravely ahead. &lt;/p&gt;
&lt;p&gt;A few weeks ago, we hit a really weird problem where an automated build running on an integration server was detecting active FxCop rule violations that couldn&amp;#39;t be duplicated on any developer machines. Several of us tried clean check outs, rebuilding, etc., but without any success at reproducing the problems seen in the automated build. In retrospect, it seems painfully obvious, but the namespace casing problem (which also tended to raise its ugly head in a Visual Studio vs. automated build disjunction with respect to C# callers) didn&amp;#39;t occur to me until I was stuck in traffic that evening. It was the first thing I checked the next morning and, sure enough, the exclusions were registered under the &amp;quot;Something&amp;quot; namespace, but the classes compiled in the automated build now fell under the &amp;quot;SomeThing&amp;quot; namespace. &lt;/p&gt;
&lt;p&gt;Some lessons learned: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;FxCop is case-sensitive.&lt;/li&gt;
&lt;li&gt;The gremlins actually lived in the VB compiler. (Luckily, they&amp;#39;ve been evicted, but the nasty smells are lingering.)&lt;/li&gt;
&lt;li&gt;Giving an &amp;quot;aha!&amp;quot; smack to one&amp;#39;s forehead while stuck in traffic will earn some very concerned looks from drivers of neighbouring vehicles.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=894175" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/FxCop/default.aspx">FxCop</category></item><item><title>FxCop backlog themes: Exceptions</title><link>http://msmvps.com/blogs/calinoiu/archive/2007/05/05/fxcop-backlog-themes-exceptions.aspx</link><pubDate>Sat, 05 May 2007 16:31:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:891514</guid><dc:creator>calinoiu</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=891514</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=891514</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2007/05/05/fxcop-backlog-themes-exceptions.aspx#comments</comments><description>&lt;p&gt;Since I started monitoring traffic on this blog a little more closely about a week ago, I had the unexpected surprise that the posts on HTML encoding and server vs. client cultures were getting a lot more hits than I expected. I had been planning on starting a series of &amp;quot;how to&amp;quot; posts on those topics this weekend, but that was before &lt;a href="http://davidkean.net/"&gt;David Kean&lt;/a&gt; from the &lt;a href="http://blogs.msdn.com/fxcop/"&gt;FxCop team&lt;/a&gt; was kind enough to direct a bunch of folks my way with &lt;a href="http://blogs.msdn.com/fxcop/archive/2007/05/04/dealing-with-a-code-analysis-backlog.aspx"&gt;a post about my recent FxCop posts&lt;/a&gt;. Since it would seem that I&amp;#39;ve now got quite a few new subscribers who are interested in FxCop, I figured I might as well continue on that theme for a while... &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Jumping the gun&lt;/h3&gt;
&lt;p&gt;I&amp;#39;ve got exception stuff on the brain this morning, so that&amp;#39;s what I&amp;#39;m going to write about. However, if you have decided to tackle &lt;a href="http://msmvps.com/blogs/calinoiu/archive/2007/04/22/fxcop-and-the-big-bad-backlog.aspx"&gt;an FxCop backlog&lt;/a&gt;, exceptions are probably not the first major theme you should cover. Then again, even assuming that my recent posts have inspired you to immediately start a backlog winnowing project, you should still be at least a month away from covering any major theme. I&amp;#39;m going to try to write about the much easier disposition and finalization topic within the next couple of weeks. Heck, it might even happen tomorrow morning if I don&amp;#39;t get coerced into some sort of housework. In the meantime, just keep in mind that the sequence in which I end up covering the topics here isn&amp;#39;t necessarily the sequence in which you&amp;#39;ll want to cover them in your backlog process. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Starting from scratch &lt;/h3&gt;
&lt;p&gt;Unless your team already has very specific guidelines in place around the generation and handling of exceptions (along with training and code reviews to reinforce those guidelines), it&amp;#39;s pretty safe to assume that there is a &lt;i&gt;very&lt;/i&gt; wide variety of exception treatment in your code base. In addition, the developers on your team likely have similarly disparate understandings of when and how exceptions ought to be generated and handled. Instead of jumping right into covering the existing FxCop rules around exceptions, it would probably be a much better idea to start with some training around the basics of exceptions. Chances are excellent that individual developers will be carrying quite a bit of baggage based on their experiences with exception treatment in other languages or platforms, and you will most likely need to devote quite a bit of time to dispelling inappropriate preconceptions. &lt;/p&gt;
&lt;p&gt;Here are a few resources that you may wish to consult during your exception training: &lt;/p&gt;
&lt;ul&gt;
&lt;li class="spaced"&gt;&lt;i&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms229014.aspx"&gt;The .NET Framework Design Guidelines for Exceptions&lt;/a&gt;&lt;/i&gt; &lt;br /&gt;Some parts are a bit outdated, and the formatting doesn&amp;#39;t necessarily make for easy reading, but this is probably still the best place to start.&lt;/li&gt;
&lt;li class="spaced"&gt;&lt;i&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/5b2yeyab.aspx"&gt;The .NET Framework Developer&amp;#39;s Guide to Handling and Throwing Exceptions&lt;/a&gt;&lt;/i&gt; &lt;br /&gt;Some parts are very basic, but the &lt;a href="http://msdn2.microsoft.com/en-us/library/seyhszts.aspx"&gt;Best Practices for Handling Exceptions&lt;/a&gt; section is good complement to the design guidelines.&lt;/li&gt;
&lt;li class="spaced"&gt;&lt;i&gt;&lt;a href="http://blogs.msdn.com/kcwalina/search.aspx?q=exception&amp;amp;p=1"&gt;Krzysztof Cwalina&amp;#39;s posts on exceptions&lt;/a&gt;&lt;/i&gt; &lt;br /&gt;Most of the information contained in these posts ought to be in the official design guidelines documentation on MSDN. Unfortunately, since the latter content doesn&amp;#39;t seem to get updated all the often, you&amp;#39;ll need to read Krzysztof&amp;#39;s posts as well.&lt;/li&gt;
&lt;li class="spaced"&gt;&lt;i&gt;The FxCop team FAQs on &lt;a href="http://blogs.msdn.com/fxcop/archive/2007/01/22/faq-what-exception-should-i-throw-instead-of-the-reserved-exceptions-found-by-donotraisereservedexceptiontypes.aspx"&gt;which exception types to throw&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/fxcop/archive/2006/06/14/FAQ_3A00_-Why-does-FxCop-warn-against-catch_2800_Exception_29003F00_-_2D00_-Part-1-_5B00_Nick-Guerrera_5D00_.aspx"&gt;why you should catch System.Exception&lt;/a&gt;&lt;/i&gt; &lt;br /&gt;By a stroke of luck, the &amp;quot;what to throw&amp;quot; FAQ came out just as we were wrapping up the exceptions topic at &lt;a href="http://www.finrad.com/"&gt;FinRad&lt;/a&gt;, which saved me the trouble of writing a very similar set of guidelines for internal consumption.&lt;/li&gt;
&lt;li class="spaced"&gt;&lt;i&gt;&lt;a href="http://blogs.msdn.com/ricom/search.aspx?q=exception&amp;amp;p=1"&gt;Rico Mariani&amp;#39;s posts on the costs of exceptions&lt;/a&gt;&lt;/i&gt; &lt;br /&gt;This content is helpful if you&amp;#39;re trying to understand the cost of exception handling, but watch out for a bit of performance-oriented bias. If you&amp;#39;re concerned about the usability of your APIs, you&amp;#39;ll probably end up wanting to throw exceptions a little more often than Rico might like. ;)&lt;/li&gt;
&lt;li class="spaced"&gt;&lt;i&gt;&lt;a href="http://blogs.msdn.com/cbrumme/archive/2003/10/01/51524.aspx"&gt;Chris Brumme&amp;#39;s post on the exception model&lt;/a&gt;&lt;/i&gt; &lt;br /&gt;Interesting as it is, this isn&amp;#39;t likely to be required reading for most folks on your team. However, it is something you might want to read if you&amp;#39;re going to be the one giving the training on the exception topic.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;If you&amp;#39;re concerned about globalization and localization issues, you might also want to have a look at my post on &lt;a href="http://msmvps.com/blogs/calinoiu/archive/2006/06/30/103426.aspx"&gt;client vs. server cultures&lt;/a&gt;. The disparity between application user and administrator languages can present challenges when emitting localized exception messages for any application, and it&amp;#39;s something you may wish to consider as you develop your internal exception generation guidelines, even if you don&amp;#39;t happen to be writing web applications. &lt;/p&gt;
&lt;h3&gt;The built-in rules&lt;/h3&gt;
&lt;p&gt;As part of the exceptions theme, you&amp;#39;ll want to start activating the FxCop rules that touch on exception generation and handling. The following table lists the rules available in FxCop 1.35 and Visual Studio 2005 static analysis: &lt;/p&gt;
&lt;table class="" cellspacing="0" cellpadding="4"&gt;

&lt;tr&gt;
&lt;th class=""&gt;Category&lt;/th&gt;
&lt;th class=""&gt;Rule&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="" rowspan="2"&gt;Design&lt;/td&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms182137(VS.80).aspx"&gt;DoNotCatchGeneralExceptionTypes&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/bb264484(vs.80).aspx"&gt;ExceptionsShouldBePublic&lt;/a&gt;&lt;sup&gt;1&lt;/sup&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="" rowspan="2"&gt;Security&lt;/td&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-US/library/bb264489(vs.80).aspx"&gt;CatchNonClsCompliantExceptionsInGeneralHandlers&lt;/a&gt;&lt;sup&gt;1&lt;/sup&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-US/library/ms182322(VS.80).aspx"&gt;WrapVulnerableFinallyClausesInOuterTry&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="" rowspan="4"&gt;Usage&lt;/td&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-US/library/ms182337(VS.80).aspx"&gt;DoNotRaiseExceptionsInFilterBlocks&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-US/library/ms182338(VS.80).aspx"&gt;DoNotRaiseReservedExceptionTypes&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-US/library/ms182347(VS.80).aspx"&gt;InstantiateArgumentExceptionsCorrectly&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;a href="http://msdn2.microsoft.com/en-US/library/ms182363(VS.80).aspx"&gt;RethrowToPreserveStackDetails&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;
&lt;p&gt;I suppose that it could be argued that &lt;a href="http://msdn2.microsoft.com/en-US/library/ms182273(VS.80).aspx"&gt;Usage.DoNotIgnoreMethodResults&lt;/a&gt; might also be worth including while activating exception rules. If your team is resistant to the idea of throwing exceptions instead of using failure return codes, then a bit of time cleaning up violations of this rule might be just the thing to convince them. Otherwise, it&amp;#39;s probably safe to activate this rule whenever it otherwise seems reasonable during your backlog process. If you&amp;#39;re following the guidelines, you&amp;#39;ll probably want to fix most violations of this rule by modifying the invoked method to throw exceptions rather than return a status code, which is a breaking change for public methods, and scheduling breaking changes can be a wee bit tricky. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Custom rules&lt;/h3&gt;
&lt;p&gt;If you&amp;#39;ve read the design guidelines concerning exceptions, it should be pretty obvious that the above eight rules don&amp;#39;t exactly cover all the potential problems for which you might want to screen. Here are a few custom rules for exceptions that we&amp;#39;re either already using at &lt;a href="http://www.finrad.com/"&gt;FinRad&lt;/a&gt; or will be introducing once we get a little further along in the backlog cleanup: &lt;/p&gt;
&lt;ul&gt;
&lt;li class="spaced"&gt;&lt;i&gt;Do not throw System.NotImplementedException&lt;/i&gt;&lt;br /&gt;Pretty obvious, although you&amp;#39;ll occasionally need to create temporary exclusions, particularly for when someone checks in a class skeleton to be fleshed out by somebody else. Also, as a bit of side note, when you introduce this guideline, you might want to stress that the exception signifies that the code is not implemented &lt;i&gt;yet&lt;/i&gt;, not that it&amp;#39;s not implemented &lt;i&gt;here&lt;/i&gt;. For &amp;quot;not implemented here&amp;quot;, you should be using System.NotSupportedException instead.&lt;/li&gt;
&lt;li class="spaced"&gt;&lt;i&gt;Methods that throw System.NotSupportedException should not include other instructions&lt;/i&gt;&lt;br /&gt;Simple as it might seem, this rule is a bit tricky to author since the VB compiler has the nasty habit of adding extra instructions (e.g.: return statements) to methods. Also, one needs to keep in mind that a custom message might be provided for the exception, and that message might be retrieved via a method call.&lt;/li&gt;
&lt;li class="spaced"&gt;&lt;i&gt;Throw System.ComponentModel.InvalidEnumArgumentException for an invalid enum argument value&lt;/i&gt;&lt;br /&gt;Not really relevant to the rule itself, but it&amp;#39;s really annoying that this particular exception lives in the System.ComponentModel namespace rather than System.&lt;/li&gt;
&lt;li class="spaced"&gt;&lt;i&gt;An argument exception should be thrown directly from the method whose argument is being validated&lt;/i&gt;&lt;br /&gt;I had hoped that the parameter name verification on &lt;a href="http://msdn2.microsoft.com/en-us/library/ms182347(vs.80).aspx"&gt;Usage.InstantiateArgumentExceptionsCorrectly&lt;/a&gt; would cover this issue but, after looking at the rule logic via &lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;Reflector&lt;/a&gt;, I&amp;#39;ve decided that a custom rule is going to be need for this one. I&amp;#39;m planning on activating it at the same time as &lt;a href="http://msdn2.microsoft.com/en-us/library/ms182182(vs.80).aspx"&gt;Design.ValidateArgumentsOfPublicMethods&lt;/a&gt; (which will definitely be happening before we move to &lt;a href="http://msmvps.com/blogs/calinoiu/archive/2007/04/28/control-flow-engine-200-2007-rip.aspx"&gt;Orcas&lt;/a&gt; &amp;lt;gdr&amp;gt;).&lt;/li&gt;
&lt;li class="spaced"&gt;&lt;i&gt;Use recommended exception logging methods&lt;/i&gt;&lt;br /&gt;In order to make logged exceptions more noticeable, we decided to create a new helper method that is capable of writing exception details to both a central repository and whatever target location was previously used. The decentralized logging problem was the consequence of an application architecture that you may not share, so this might not be particularly relevant for your team. However, if you do have similarly decentralized logging, you may want to consider a similar approach. If you do decide to add a special exception logging method, then you&amp;#39;ll probably also want to add a custom rule to verify that it&amp;#39;s being used.&lt;/li&gt;
&lt;li class="spaced"&gt;&lt;i&gt;Review use of System.Diagnostics.Debug methods&lt;/i&gt;&lt;br /&gt;Some folks have a tendency to use Debug.Assert or Debug.Fail where they really ought to be throwing exceptions.&lt;/li&gt;
&lt;li class="spaced"&gt;&lt;i&gt;Review catch without throw&lt;/i&gt;&lt;br /&gt;Last but definitely not least, this is our &amp;quot;do not eat exceptions&amp;quot; rule. Unfortunately, fixing an undesirable violation of this rule can be very time-consuming, but discovering places where an application is hiding exceptions has tremendous impact on reliability, and the short-term cost is well worth the long-term benefit.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Personally, I&amp;#39;d love to see at least the more generally useful rules from the above list make it into the rule set shipped by Microsoft. I seem to remember seeing something from the code analysis team that promised some new rules around exceptions for Orcas, but I can&amp;#39;t find it anymore, and I haven&amp;#39;t seen any new exception rules either. It&amp;#39;s a pity, because I was really hoping to get rid of my custom rules, particularly the less than ideal verification for other instructions in methods that throw System.NotSupportedException...&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;sup&gt;1&lt;/sup&gt;This rule is not available in Visual Studio 2005, but it is shipped with both FxCop 1.35 and Orcas beta 1. &lt;br /&gt;&lt;br /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=891514" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/FxCop/default.aspx">FxCop</category></item><item><title>FxCop backlogs: Some rules for rule activation</title><link>http://msmvps.com/blogs/calinoiu/archive/2007/04/29/fxcop-backlogs-some-rules-for-rule-activation.aspx</link><pubDate>Sun, 29 Apr 2007 14:38:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:883208</guid><dc:creator>calinoiu</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=883208</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=883208</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2007/04/29/fxcop-backlogs-some-rules-for-rule-activation.aspx#comments</comments><description>&lt;p&gt;If you&amp;#39;ve decided to try to tackle an &lt;a href="http://msmvps.com/blogs/calinoiu/archive/2007/04/22/fxcop-and-the-big-bad-backlog.aspx"&gt;FxCop violation backlog&lt;/a&gt;, one of the first issues you&amp;#39;re going to face is deciding which rules to activate when. Here are some general guidelines... &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Starting out&lt;/h3&gt;
&lt;p&gt;When you first begin the backlog clean-up process, you&amp;#39;re going to need to introduce the FxCop tool to your team (assuming, of course, that you&amp;#39;re not already using FxCop for new projects). In order to focus on mastering the tool and the cleanup process before diving into &amp;quot;difficult&amp;quot; rules, you&amp;#39;ll want to pick a few rules to activate that meet the following criteria: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The rule itself should be easy to understand with minimal background explanation.&lt;/li&gt;
&lt;li&gt;Violations of the rule should be easy to fix.&lt;/li&gt;
&lt;li&gt;Your code should contain very few violations of the rule.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;My favourite introductory rule is &lt;a href="http://msdn2.microsoft.com/en-us/library/ms182272(VS.80).aspx"&gt;DoNotConcatenateStringsInsideLoops&lt;/a&gt;. Unfortunately, it&amp;#39;s &lt;a href="http://msmvps.com/blogs/calinoiu/archive/2007/04/28/control-flow-engine-200-2007-rip.aspx"&gt;slated to disappear in Orcas&lt;/a&gt;, so you might want to get a start on that backlog cleanup soon if you want to use it. ;) For finding other candidate &amp;quot;early&amp;quot; rules, the best approach would generally be to count your violations per rule, then look for any rules with a violation count of between approximately 5 and 20 that also meet the &amp;quot;easy to understand&amp;quot; and &amp;quot;easy to fix&amp;quot; criteria. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;If it ain&amp;#39;t broke, it don&amp;#39;t need fixin&amp;#39;...&lt;/h3&gt;
&lt;p&gt;Another thing you&amp;#39;ll want to do fairly early in the process is activate rules for which you have no existing violations. Even though this lock down might seem very important with respect to preventing additional backlog problems, it should probably wait until you&amp;#39;re a few weeks into the cleanup process, and the team is starting to get reasonably comfortable with the whole thing. Don&amp;#39;t worry too much about this delay causing new rule breaking -- if you&amp;#39;ve gone this long without breaking those rules, chances are pretty slim that you&amp;#39;ll break them in the next three weeks or so. ;) &lt;/p&gt;
&lt;p&gt;Simple as it may seem, there are still a few things to consider as you select &amp;quot;no violation&amp;quot; rules to activate: &lt;/p&gt;
&lt;ol&gt;
&lt;li style="PADDING-BOTTOM:0.5em;"&gt;Some of these rules will have no violations because your team has been actively avoiding some problem. Take this opportunity to highlight that they&amp;#39;ve been doing the right thing and confirm what that &amp;quot;right thing&amp;quot; is since newer team members may not be aware of it.&lt;/li&gt;
&lt;li style="PADDING-BOTTOM:0.5em;"&gt;Some of the rules will have no violations because your project doesn&amp;#39;t touch on the area covered by the rule. For example, if you don&amp;#39;t interact with native APIs, there are several rules around p/invoke calls that you won&amp;#39;t have broken. Given that your team is unlikely to start breaking these &amp;quot;irrelevant&amp;quot; rules, you can safely activate them without too much explanation. However, you should at least mention that you are activating the rule, give a quick description of its significance, and explain why it&amp;#39;s not likely to be violated in the target code base. This approach will ensure that the team is aware of the rule should it eventually become more relevant due to changes in the project scope.&lt;/li&gt;
&lt;li&gt;Some rules (but not very many) will have no violations almost by chance alone and will require more in-depth explanation than you may wish to allot this early in your process. You might want to consider delaying activating such rules until you have a more appropriate opportunity to provide more in-depth training on the rule.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;
&lt;h3&gt;Mix and match&lt;/h3&gt;
&lt;p&gt;As you start activating rules, you&amp;#39;ll soon realize that some rule violations are a lot quicker and easier to fix than others. For example, fixing a violation of &lt;a href="http://msdn2.microsoft.com/en-us/library/ms182363(VS.80).aspx"&gt;RethrowToPreserveStackDetails&lt;/a&gt; usually takes seconds, while there are a few rules for which a fix may take hours. It&amp;#39;s important that your immediate fix backlog contain a mix of problems, both with respect to difficulty and fix duration. The quick and easy fixes will provide small tasks that any developer will be able to perform, and they&amp;#39;re nice little &amp;quot;fillers&amp;quot; for those five minute blocks when you&amp;#39;re waiting on something like a pre-commit test run for another task. They&amp;#39;ll also help keep the momentum going when you&amp;#39;ve got a backlog of &amp;quot;big&amp;quot; problems to address. If you only have big problems in the backlog at any given time, the overall fix rate will be slow, and that&amp;#39;s just plain depressing for everyone.&lt;/p&gt;
&lt;p&gt;Some fixes will require considerable knowledge of a particular area of your product, and one approach to handling these would be have developers fix such problems in their own areas of responsibility. However, you may also want to view such fixes as an opportunity for a bit of cross-training. Either way, you should make sure that your immediate backlog doesn&amp;#39;t only contain violations against a limited subset of your product. Any given developer on your team should be able to draw problems from the backlog pool at any given time. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;Slow down, you crazy child&lt;/h3&gt;
&lt;p&gt;Now and then, your immediate fix backlog is going to grow just a bit too big. This usually happens because you&amp;#39;ve activated a rule with a large number of violations and/or for which violations are expensive to fix. In order to prevent the backlog from growing even more, you&amp;#39;re going to have to stop activating new rules for a while. There are basically two things you can do to avoid losing momentum because of this hiatus. The first is pretty trivial, and simply involves having developers fix violations during the time that would normally be allotted to introducing new rules. If you&amp;#39;re concerned that the fix rate has dropped off because developers have fallen out of the habit of working on the backlog, then having everyone work on fixing problems at the same time like this can be one way of &amp;quot;rebooting&amp;quot; the process. However, if developers are already spending the time they ought to be on the backlog, a fix session like this isn&amp;#39;t necessarily a very effective use of anyone&amp;#39;s time. &lt;/p&gt;
&lt;p&gt;The other &amp;quot;delaying tactic&amp;quot; is to treat the increased between-rule activation delay as an opportunity to provide more in-depth training, particularly for rules where a lot of background information may be required. It can help quite a bit to divide such rules into themes, with background training on any given theme spanning several weeks. A few obvious themes are: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;finalization and disposition,&lt;/li&gt;
&lt;li&gt;exceptions, and &lt;/li&gt;
&lt;li&gt;code access security.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Custom rules&lt;/h3&gt;
&lt;p&gt;As you tackle your backlog, you&amp;#39;ll probably start to identify some less than desirable usage patterns that aren&amp;#39;t covered by existing rules. While it can be quite tempting to immediately activate a new custom rule based on such a discovery, don&amp;#39;t forget that you have plenty of built-in rules that aren&amp;#39;t yet active either. Your custom rule should go into the same backlog &amp;quot;pot&amp;quot; as the built-in rules, and it should be activated when most appropriate to your backlog process, which may or may not be when you first discover the problem that the rule covers. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;How far, how fast?&lt;/h3&gt;
&lt;p&gt;Obviously, the rate at which you will be able to activate rules will depend quite a bit on the size of the backlog and rate at which your team will be able to fix violations. However, you should also expect the activation rate to drop off over time as you start to activate rules that are difficult to fix and rules with large numbers of violations. Given that you may also start adding custom rules, the proportion of rules activated may drop even though you&amp;#39;re not inactivating any rules. Nothing exactly surprising in any of that, but it does mean that you shouldn&amp;#39;t use the rate of rule activation as an important indicator of your backlog clearing progress. &lt;/p&gt;&lt;br /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=883208" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/FxCop/default.aspx">FxCop</category></item><item><title>Control flow engine, 200?-2007, RIP</title><link>http://msmvps.com/blogs/calinoiu/archive/2007/04/28/control-flow-engine-200-2007-rip.aspx</link><pubDate>Sat, 28 Apr 2007 12:38:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:881997</guid><dc:creator>calinoiu</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=881997</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=881997</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2007/04/28/control-flow-engine-200-2007-rip.aspx#comments</comments><description>&lt;h3&gt;Surprise! (not the good kind)&lt;/h3&gt;
&lt;p&gt;If you use FxCop or Visual Studio Static Analysis and haven&amp;#39;t yet started playing with Orcas, you may be in for a bit of an unpleasant surprise. While the code analysis team is doing &lt;a href="http://blogs.msdn.com/fxcop/archive/2007/02/28/announcing-visual-studio-code-metrics.aspx"&gt;all sorts of interesting things for Orcas&lt;/a&gt;, one somewhat less desirable change you probably haven&amp;#39;t heard about yet is &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=270831"&gt;removal of the control flow engine&lt;/a&gt; and, consequently, the following rules which depend upon it: &lt;/p&gt;
&lt;table class="standardPostTable" cellspacing="0" cellpadding="4" class="standardPostTable"&gt;

&lt;tr&gt;
&lt;th class=""&gt;Category&lt;/th&gt;
&lt;th class=""&gt;Rule&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;Design&lt;/td&gt;
&lt;td class=""&gt;ValidateArgumentsOfPublicMethods&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;Globalization&lt;/td&gt;
&lt;td class=""&gt;DoNotPassLiteralsAsLocalizedParameters&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="" rowspan="3"&gt;Performance&lt;/td&gt;
&lt;td class=""&gt;AvoidUnnecessaryStringCreation&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;DoNotCallPropertiesThatCloneValuesInLoops&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;DoNotConcatenateStringsInsideLoops&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;Reliability&lt;/td&gt;
&lt;td class=""&gt;DisposeObjectsBeforeLosingScope&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;Security&lt;/td&gt;
&lt;td class=""&gt;ReviewSqlQueriesForSecurityVulnerabilities&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="" rowspan="6"&gt;Usage&lt;/td&gt;
&lt;td class=""&gt;AttributeStringLiteralsShouldParseCorrectly&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;DisposeMethodsShouldCallBaseClassDispose&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;DoNotDisposeObjectsMultipleTimes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;LiteralsShouldBeSpelledCorrectly&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;ProvideCorrectArgumentsToFormattingMethods&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;The reasons given for removing the engine are basically that it&amp;#39;s slow, buggy, and difficult to maintain. Well, we&amp;#39;ve all had to deal with that sort of problem before, but most of us haven&amp;#39;t have the luxury of removing the nasty, old implementation without providing a replacement. I can certainly understand that the code analysis team might be under pressure to rapidly address performance problems introduced by an engine that slows any use of their product by a factor of 2 or more, but this strikes me as a case of throwing the baby out with the bath water. &lt;/p&gt;
&lt;p&gt;The one piece of good news is that there seem to be plans to eventually replace the engine. However, we supposedly won&amp;#39;t be seeing the new implementation until at least the post-Orcas release of Visual Studio, which very likely means waiting two years or more. A couple of things to consider: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;How big a backlog of violations against the missing control flow rules do you think your team will likely create in two years?&lt;/li&gt;
&lt;li&gt;Given that the code analysis team apparently considers it acceptable to remove this feature set without providing an immediate replacement, how confident are you in their ability to keep development of the replacement at a high enough priority level that it will actually ship in the post-Orcas release of Visual Studio?&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;
&lt;h3&gt;On again, off again...&lt;/h3&gt;
&lt;p&gt;Let&amp;#39;s assume for the moment that the performance hit caused by the control flow engine really does prevent some folks from using FxCop. Even if it doesn&amp;#39;t, performance improvements are probably pretty high on many folks&amp;#39; wish lists for FxCop, and it would seem likely that the code analysis team has to put up with a lot of complaining on that front. In addition, there are known bugs in the control flow engine and rules, and those problems may cause both some minor inconvenience as well as false confidence that rules are being applied where they&amp;#39;re not. Are these really sufficient justifications for eliminating the control flow engine entirely in Orcas? &lt;/p&gt;
&lt;p&gt;Rather than removing the engine, I would much rather see it become an optional, disabled-by-default component. This scenario would remove the potential performance obstacle for new users while still allowing existing customers to at least keep up the same level of screening that was previously applied. If there is concern on the part of the code analysis team that users aren&amp;#39;t aware of the buggy, partial screening against control flow rules, the feature that allows enabling of the control flow engine could include whatever warnings they deem necessary.&lt;/p&gt;
&lt;p&gt;Given that Orcas is already in beta, it seems likely that re-introducing the control flow engine might be too big a change to support. If so, another possibility might be to make it available only in the stand-alone FxCop product. Obviously, this would be a little less convenient for users of Visual Studio Code Analysis. However, it would at least allow such users to make their own performance/convenience/quality trade-off decisions rather than having a potentially unsuitable decision imposed upon them by the complete absence of the engine. &lt;/p&gt;
&lt;p&gt;I&amp;#39;ve already submitted &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=270831"&gt;a suggestion&lt;/a&gt; regarding re-introduction of the control flow engine as an optional component on the &lt;a href="http://connect.microsoft.com/"&gt;Microsoft Connect site&lt;/a&gt;. If you&amp;#39;re concerned about the removal of the engine, perhaps it&amp;#39;s time to consider voicing your opinion there as well... &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=881997" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/FxCop/default.aspx">FxCop</category></item><item><title>FxCop and the big, bad backlog</title><link>http://msmvps.com/blogs/calinoiu/archive/2007/04/22/fxcop-and-the-big-bad-backlog.aspx</link><pubDate>Sun, 22 Apr 2007 13:19:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:859797</guid><dc:creator>calinoiu</dc:creator><slash:comments>11</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=859797</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=859797</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2007/04/22/fxcop-and-the-big-bad-backlog.aspx#comments</comments><description>&lt;P&gt;A few months ago, I gave a presentation on using FxCop at the &lt;A href="http://www.guvsm.net/"&gt;Montreal Visual Studio Users Group&lt;/A&gt;. The material was divided into two main topics: (a) the mechanics of using FxCop and (b) integrating FxCop use into a development process. During the first part of the talk, &lt;A href="http://geekswithblogs.net/etiennetremblay/"&gt;some&lt;/A&gt; &lt;A href="http://www.mariocardinal.com/"&gt;members&lt;/A&gt; of the peanut gallery kept piping up with questions about what one can do to handle the huge number of FxCop rule violations that an existing code base will have when one first runs FxCop against it. Lucky for me, most of the second part of the talk covered exactly that problem, and I managed to finish the evening without having any rotten produce lobbed in my direction. However, their questions did confirm my suspicion that dealing with the backlog problem is a topic of potential interest to folks, so it's one I might as well spend a bit of time writing about...&lt;/P&gt;&lt;BR&gt;
&lt;H3&gt;No backlog?&amp;nbsp; No problem.&lt;/H3&gt;
&lt;P&gt;Before tackling the hard part of the backlog problem, let's look at the easy part. If you're starting a new project, the easiest way to handle the backlog issue is to never develop a backlog in the first place. The way to do this is to start running FxCop with all rules activated from the moment you first set up your project(s) and to fix problems (or flag true exclusions) before each and every check-in.&lt;/P&gt;
&lt;P&gt;This may seem like a lot of work and, to be honest, it will almost certainly add noticeable overhead at the very beginning, but the additional effort required will probably taper off more quickly than you might expect. Within a week or two, most individual developers should be over the learning curve "hump" with respect to the FxCop tool itself. What might surprise you is that it probably won't take much longer for most developers to become familiar with the rules that touch their own work and to stop introducing new violations of those rules. This will, of course, vary depending on the spectrum of tasks that any given developer performs, but most developers in anything but the very smallest shops are likely working on fairly similar tasks from one week to the next. &lt;/P&gt;
&lt;P&gt;Another issue on the "no backlog" side of things is that you might need to &lt;I&gt;occasionally&lt;/I&gt; create temporary exclusions (&lt;I&gt;e.g.&lt;/I&gt;: when you've added the first class to a namespace, but the others that would eventually prevent &lt;CODE&gt;Design.AvoidNamespacesWithFewTypes&lt;/CODE&gt; from firing don't yet exist), and allowing these to accumulate could also create a backlog problem. The way to prevent this is to avoid them where possible and clean them up as soon as possible when their creation can't be avoided. I would recommend creating a project work item for removing any given temporary exclusion immediately before adding the exclusion itself. A final check that they have all been removed should be part of a pre-release checklist, and the release in question should be the earliest you can isolate (&lt;I&gt;e.g.&lt;/I&gt;: internal release to QA). &lt;/P&gt;&lt;BR&gt;
&lt;H3&gt;And now for the hard stuff...&lt;/H3&gt;
&lt;P&gt;If, like many folks with a medium-to-large existing code base, you've run FxCop and been overwhelmed at the thousands or tens of thousands of violations that it spits out, what can you possibly do? The most common reaction seems to be essentially giving up on the idea of using FxCop for that product. That's unfortunate, partly because the existing problems will go unaddressed until they manifest as user-noticeable bugs, but also because the product will continue to accumulate new problems as development progresses. &lt;/P&gt;
&lt;P&gt;Another path is to disregard the existing backlog and follow the "no backlog" approach described above for new development. Since the FxCop team has produced a &lt;A href="http://blogs.msdn.com/fxcop/archive/2006/05/19/making-it-easier-to-move-from-fxcop-to-visual-studio-code-analysis-jeffrey-van-gogh.aspx"&gt;tool&lt;/A&gt; to help facilitate this approach, I presume that it is a relatively common choice. Unfortunately, while it does avoid the problem of accumulating new violations, it doesn't address the existing backlog particularly well. &lt;/P&gt;
&lt;P&gt;So... Can one do something to both prevent new problems and clean up the old problems? At &lt;A href="http://www.finrad.com/"&gt;FinRad&lt;/A&gt;, we started a process in late September to do just that. One of the things that was immediately obvious was that "hiding" the existing backlog wasn't likely to be terribly helpful if our goal was to eventually clean it all up. Part of the problem is that folks would probably become rapidly inured to the large volume of existing exclusions. Another, potentially more important issue, is that a big backlog is just plain too depressing.&lt;/P&gt;
&lt;P&gt;Rather than activating all rules at the beginning and excluding all existing rule violations (even temporarily), we decided to adopt a process whereby rules are activated one-by-one. Once a rule is activated, its existing violations are added to the immediate backlog and nobody is allowed to introduce new violations. In addition, we decided to provide training on the newly activated rules rather than expecting individual developers to do all the rule reason and fix approaches research on their own. The basic outline of this process is:&lt;/P&gt;
&lt;OL&gt;
&lt;LI style="PADDING-BOTTOM:0.5em;"&gt;Every week, a new set of rules to activate is selected.&lt;/LI&gt;
&lt;LI style="PADDING-BOTTOM:0.5em;"&gt;We have a one hour training session on the new rules. This training includes: 
&lt;UL&gt;
&lt;LI&gt;any background information that is required to understand the rules,&lt;/LI&gt;
&lt;LI&gt;the specific problems that the rules are meant to address,&lt;/LI&gt;
&lt;LI&gt;recommended approaches to fixing rule violations, and&lt;/LI&gt;
&lt;LI&gt;reasons for which it is acceptable to create exclusions for violations.&lt;/LI&gt;&lt;/UL&gt;In addition, progress statistics are presented at each training session so that everyone is aware of where we stand with respect to the existing backlog. &lt;/LI&gt;
&lt;LI style="PADDING-BOTTOM:0.5em;"&gt;Immediately after the training session, the new rules are activated, and existing violations are added to the backlog by creating "TODO" exclusions. &lt;/LI&gt;
&lt;LI style="PADDING-BOTTOM:0.5em;"&gt;As of the activation of a rule, no new violations are accepted.&lt;/LI&gt;
&lt;LI style="PADDING-BOTTOM:0.5em;"&gt;Each developer is supposed to spend two hours per week fixing rule violations from the backlog.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;In practice, this exact process isn't followed to the letter every week. Besides the obvious impossibility of grabbing three hours of each developer's time every single week, there are also all sorts of picky details around which rules can/should be activated when, and what one should do to keep the momentum going when the size of the backlog jumps because of the activation of a single rule. There's also the question of what sort of hit we're taking with respect to new violations against the rules that haven't yet been activated. However, I think I'll keep all of that as meat for further blog posts for now...&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=859797" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/FxCop/default.aspx">FxCop</category></item><item><title>No rules in your FxCop rule assembly?</title><link>http://msmvps.com/blogs/calinoiu/archive/2007/04/21/no-rules-in-your-fxcop-rule-assembly.aspx</link><pubDate>Sat, 21 Apr 2007 12:39:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:852672</guid><dc:creator>calinoiu</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=852672</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=852672</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2007/04/21/no-rules-in-your-fxcop-rule-assembly.aspx#comments</comments><description>&lt;p&gt;Since I posted an FxCop rule sample over at &lt;a href="http://bordecal.mvps.org"&gt;bordecal.mvps.org&lt;/a&gt;, it&amp;#39;s rapidly become the most popular content on the site. Not something I expected but, given that I have trouble coming up with blogging topics and there seems to be some interest in FxCop, I figured I might as well spend a lovely Saturday morning writing about it... (Actually, I&amp;#39;m pretty much just killing time while waiting for a tire change, so please feel free to keep that &amp;quot;get a life&amp;quot; comment to yourself. &amp;lt;g&amp;gt;)&lt;/p&gt;
&lt;p&gt;There&amp;#39;s all sorts of stuff I could (and will try to) write about FxCop use, but one thing that jumped out at me this week was quite a few searches for &amp;quot;no FxCop rules could be found&amp;quot; landing on my rule sample page, so I guess I&amp;#39;ll start with that...&lt;/p&gt;
&lt;p&gt;There are several reasons why FxCop might have trouble finding rules in a custom rule assembly:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;i&gt;There are no rule classes.&lt;/i&gt;
&lt;p&gt;If you haven&amp;#39;t added any rule classes to your assembly, it shouldn&amp;#39;t be too much of a problem to figure out why FxCop can&amp;#39;t find them. ;)&lt;/p&gt;
&lt;p&gt;Another problem might be that your rule classes don&amp;#39;t implement the necessary rule interfaces. If you&amp;#39;ve done the usual thing and created your rules as subclasses of &lt;code&gt;Microsoft.FxCop.Sdk.Introspection.BaseIntrospectionRule&lt;/code&gt;, then you&amp;#39;ve got the interface problem covered. However, if you&amp;#39;re rolling your own rules from scratch, you&amp;#39;re probably going to have to do quite a bit more work... (Which I&amp;#39;ve never done, so I have no idea what&amp;#39;s the minimum required. My first guess would be &lt;code&gt;IRule&lt;/code&gt;, but that seems rather useless since there are no problem collections exposed until one gets to &lt;code&gt;IControlFlowRule&lt;/code&gt; or &lt;code&gt;IIntrospectionRule&lt;/code&gt;.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;i&gt;You&amp;#39;ve forgotten to add an embedded rules resource file.&lt;/i&gt;
&lt;p&gt;This is probably the most common problem for beginners. If you&amp;#39;re not sure what the rule resource file should contain, grab yourself a copy of &lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;Reflector&lt;/a&gt;, and take a look at the &lt;code&gt;Microsoft.FxCop.Rules.Design.DesignRules.xml&lt;/code&gt; embedded resource in the &lt;code&gt;DesignRules.dll&lt;/code&gt; file that ships with FxCop or Visual Studio Static Analysis.&lt;/p&gt;
&lt;p&gt;Also, remember that this file must be set to be an embedded resource. If the file doesn&amp;#39;t end up in your compiled assembly, FxCop won&amp;#39;t be able to find it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;em&gt;You&amp;#39;ve incorrectly identified the embedded rules resource file in which the data for your rule class can be found.&lt;/em&gt;&lt;i&gt;&lt;/i&gt;
&lt;p&gt;Once you&amp;#39;ve created your embedded rules resource file, this may be the next problem you hit. If you&amp;#39;re inheriting from &lt;code&gt;BaseIntrospectionRule&lt;/code&gt;, you must pass the full resource file name (minus the &lt;code&gt;.xml&lt;/code&gt; extension) when invoking the protected &lt;code&gt;BaseIntrospectionRule&lt;/code&gt; constructor. Since all the custom rules in a given assembly will typically use the same rules resource file, one would usually create a base class from which they would all inherit. The rule base class might look something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;namespace Bordecal.FxCop.Rules
{
	internal abstract class IntrospectionRule : BaseIntrospectionRule
	{
		protected IntrospectionRule(string name)
			: base(name, &amp;quot;Bordecal.FxCop.Rules.Rules&amp;quot;, typeof(IntrospectionRule).Assembly)
		{
		}
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This avoids requiring all rules to provide the resource file name, but it doesn&amp;#39;t help with figuring out what the file name ought to be in the first place.&lt;/p&gt;
&lt;p&gt;The bad news is that inferring the resource file name can be a bit tricky. It will depend on your project&amp;#39;s default namespace, as well as on where the rule file resides within your project&amp;#39;s directory hierarchy. The good news is that you don&amp;#39;t need to infer the name at all. Instead, simply open your rule assembly in &lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;Reflector&lt;/a&gt;, and copy the full name of your resource file (remember to omit the &lt;code&gt;.xml&lt;/code&gt; extension):&lt;/p&gt;
&lt;p&gt;&lt;img src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/calinoiu/ResourceInReflector.png" alt="" /&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=852672" width="1" height="1"&gt;</description><enclosure url="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.85.26.72/ResourceInReflector.png" length="40439" type="image/x-png" /><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/FxCop/default.aspx">FxCop</category></item></channel></rss>