I added a partial method to some code today and StyleCop decided that it didn’t like the fact that my method did not have an access modifier. The error I received from StyleCop was:
SA1205: The partial method does not have an access modifier defined. StyleCop may not be able to determine the correct placement of the elements in the file. Please declare an access modifier for all partial methods.
Well, as you probably know, access modifiers are not valid on partial methods. I figured this was probably a bug in StyleCop and decided to try to simply ignore it. I fired up the StyleCop UI only to discover that SA1205 cannot be ignored (actually, it doesn’t even show up). Bummer. I poked around a little bit and stumbled across this post. It seems that the rule that is causing this problem is loaded from an XML file that is an embedded resource. This file controls whether rules can be disabled. Well, hoping that they maybe “locked the front door but not the back door” I tried to add it to my .StyleCop settings file directly with:
<Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.OrderingRules">
<Rules>
<Rule Name="PartialElementsMustDeclareAccess">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Analyzer>
That didn’t work either. Damn. Well, given the fact that we treat StyleCop violations as errors, I decided to redesign my code to not use partial methods. Style over function, I guess.
Update: Looks like StyleCop 4.3.1.3 has fixed this bug.