How to suppress StyleCop error SA0102 : CSharp.CsParser : A syntax error has been discovered in file when using generic type parameters attributes

Sergey Fadeev picture Sergey Fadeev · Dec 13, 2013 · Viewed 14.8k times · Source

Having the following C# code with generic type parameter attribute:

[System.AttributeUsage(System.AttributeTargets.GenericParameter)]
public class GenericParameterAttribute : System.Attribute
{
}
public class GenericClass<[GenericParameter] T>
{
}

With turned on StyleCop integration (StyleCop.targets imported in .csproj file) StyleCop returns error and compilation fails:

Error 1 SA0102 : CSharp.CsParser : A syntax error has been discovered in file ...

Without StyleCop.targets imported in .csproj file compiled ok.

Environment

I can't find code SA0102 on StyleCop documentation site http://www.stylecop.com/docs/StyleCop%20Rules.html - it seems SA0102 is not a StyleCop rule, possible it is code of internal StyleCop error.

So question: How to suppress StyleCop error SA0102?

Answer

AlexH picture AlexH · Dec 13, 2013

It seems impossible to suppress this error with this kind of attribute :

[SuppressMessage("StyleCopNameSpace", "SA0102:RuleNameHere")] 

As related in this Post, this message is displayed when StyleCop encounters an internal error:

jasonall May 18, 2010 at 10:00 PM: It is actually not possible to suppress SA0101 or SA0102. These are special case “rules” which are thrown whenever StyleCop encounters an internal error. The only workarounds for you would be to disable this file from analysis completely, or stop using optional parameters until upgrading to StyleCop 4.4.