3

Style cop will try to force you to take the underscore out of Application_Start in the Global.asax file in an mvc web application:

SP0100: Method (general) name Application_Start doesn't conform the specified style: SampleName.

But this name cannot be changed without breaking the web application (I think?).

I am having trouble writing the suppress message to bypass this rule, and also for some reason the analyzer in stylecop is not finding this error [Edit - the error is not being found because it is a StyleCop+ error] - so I am unable to auto-generate a module-level suppress message.

Can someone help with the right suppress message to use to get past this?

I have tried something along the lines of:

[module: SuppressMessage("StyleCopPlus.StyleCopPlusRules", "SP0100:AdvancedNamingRules", Scope="member", Target="Global.asax", Justification = "Some justification")]

But with no luck

Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93
DevDave
  • 6,700
  • 12
  • 65
  • 99
  • Does it work (globally) if you remove the `Scope` and `Target` attributes? I know that's not what you want, but the answer might help towards finding a solution. – Matthew Strawbridge Feb 06 '12 at 23:25
  • 1
    Haven't tried that yet I don't think but did get it working by putting the suppression directly above Application_Start() – DevDave Feb 07 '12 at 09:46
  • Ah okay. Glad you've sorted it out. I suggest you enter that as an answer yourself and mark it as correct. This will make it easier for other people to find the solution if they have the same problem. – Matthew Strawbridge Feb 07 '12 at 11:41
  • still hoping for a better answer than mine but will put it up after a day or 2 if nothing else is posted – DevDave Feb 07 '12 at 12:41

1 Answers1

5

First, StyleCop suppressions are hard to remember indeed, but the easiest way is to use them just right before your method, or before the whole class. In your case suppression attribute will look like:

[SuppressMessage("StyleCopPlus.StyleCopPlusRules", "SP0100:AdvancedNamingRules", Justification = "Global ASAX method.")]

Second, StyleCop+ is not currently able to detect Global ASAX methods, so it considers them as common methods and apply corresponding rules. Given that, you could probably use the following naming rules for "Methods (general)":

$(AaBb)
Application_$(AaBb)
Page_$(AaBb)
Session_$(AaBb)

The disadvantage here is that method Application_DoWork will not be violated, even it is not related to Global ASAX.

Finally, you could submit an issue to StyleCop+, so that it could distinguish Global ASAX methods and apply separate naming rules to them.

Oleg Shuruev
  • 1,339
  • 8
  • 10