Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SA1600 (Elements must be documented) throws InvalidCastException #1416

Closed
oatkins opened this issue Sep 8, 2015 · 4 comments
Closed

SA1600 (Elements must be documented) throws InvalidCastException #1416

oatkins opened this issue Sep 8, 2015 · 4 comments
Assignees
Milestone

Comments

@oatkins
Copy link
Contributor

oatkins commented Sep 8, 2015

I get the following exception, though I can't see what code is causing this. It has me scratching my head, since I can't work out how the parent of a method declaration could be a compilation unit.

Analyzer 'StyleCop.Analyzers.DocumentationRules.SA1600ElementsMustBeDocumented' threw the following exception:
'System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.BaseTypeDeclarationSyntax'.
   at StyleCop.Analyzers.Helpers.AccessLevelHelper.GetEffectiveAccessibility(BaseMethodDeclarationSyntax syntax, SemanticModel semanticModel, CancellationToken cancellationToken)
   at StyleCop.Analyzers.DocumentationRules.SA1600ElementsMustBeDocumented.Analyzer.HandleMethodDeclaration(SyntaxNodeAnalysisContext context)
   at StyleCop.Analyzers.AnalyzerExtensions.<>c__DisplayClass2_0`1.<RegisterSyntaxNodeActionHonorExclusions>b__0(SyntaxNodeAnalysisContext c)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass35_0`1.<ExecuteSyntaxNodeAction>b__1()
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze)'.
@sharwell
Copy link
Member

sharwell commented Sep 8, 2015

Do you have a method defined outside of a type?

@oatkins
Copy link
Contributor Author

oatkins commented Sep 8, 2015

I have 17,000 source files, so I'm not sure!

I didn't think that was ever valid C# syntax. Delegates can be outside of a type, but I wouldn't have thought that they would come through as BaseMethodDeclarationSyntax.

Could the exception have been thrown on incomplete code while I was typing in the editor? I can't reproduce that though.

@sharwell sharwell added this to the 1.0.0 Beta 10 milestone Sep 8, 2015
@oatkins
Copy link
Contributor Author

oatkins commented Sep 8, 2015

OK. I managed to reproduce this. A public method placed in the global scope is invalid, but still get analyzed, and so you still see the exception.

@hvanbakel
Copy link
Contributor

Grabbed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants