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

StackOverflow https://stackoverflow.com/questions/20563385

Domanda

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

Look for the file that you want to exclude from StyleCop in .csproj file and add the ExcludeFromStyleCop element as below

<Compile Include="<filename>.cs">
  <ExcludeFromStyleCop>True</ExcludeFromStyleCop>
</Compile>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top