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

Fix S3881: Rule should not fail on partial classes #416

Closed
nnpcYvIVl opened this issue Jun 9, 2017 · 9 comments
Closed

Fix S3881: Rule should not fail on partial classes #416

nnpcYvIVl opened this issue Jun 9, 2017 · 9 comments
Assignees
Labels
Type: Bug Exceptions and blocking issues during analysis.
Milestone

Comments

@nnpcYvIVl
Copy link

Description

This error is thrown during analysis: AD0001 Analyzer 'SonarAnalyzer.Rules.CSharp.ImplementIDisposableCorrectly' threw an exception of type 'System.ArgumentException' with message 'Syntax node is not within syntax tree'.

Related information

  • SonarC# Latest Version
  • Visual Studio 2017
@Evangelink
Copy link
Contributor

Hi @nnpcYvIVl!

Could you manage to create some small reproducer? Or at worst to share with us the class where this happens (you can send us a direct email if you are concerned about the privacy of your code).

Cheers,
Amaury

@Evangelink Evangelink added Area: Rules Type: Bug Exceptions and blocking issues during analysis. labels Jun 12, 2017
@Evangelink Evangelink added this to the 6.1 milestone Jun 12, 2017
@nnpcYvIVl
Copy link
Author

It's a large project and I haven't been able to create a small repro. I'll keep trying but for now here is the stack trace.

Severity	Code	Description	Project	File	Line	Category	Suppression State	Detail Description
Warning	AD0001	Analyzer 'SonarAnalyzer.Rules.CSharp.ImplementIDisposableCorrectly' threw an exception of type 'System.ArgumentException' with message 'Syntax node is not within syntax tree'.	CCM		1	Compiler	Active	Analyzer 'SonarAnalyzer.Rules.CSharp.ImplementIDisposableCorrectly' threw the following exception:
'Exception occurred with following context:
Compilation: Redacted
SyntaxTree: Redacted\...\Redacted.cs
SyntaxNode: public partial class Redacted ... [ClassDeclarationSyntax]@[87..967) (6,4)-(34,5)

System.ArgumentException: Syntax node is not within syntax tree
   at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.CheckSyntaxNode(CSharpSyntaxNode syntax)
   at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetSymbolInfo(ExpressionSyntax expression, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetSymbolInfo(SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken)
   at SonarAnalyzer.Helpers.SyntaxHelper.<>c__DisplayClass15_0.<ContainsMethodInvocation>b__0(InvocationExpressionSyntax e)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<OfTypeIterator>d__92`1.MoveNext()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at SonarAnalyzer.Helpers.SyntaxHelper.ContainsMethodInvocation(IEnumerable`1 syntaxNodes, SemanticModel semanticModel, Func`2 syntaxPredicate, Func`2 symbolPredicate)
   at SonarAnalyzer.Helpers.SyntaxHelper.ContainsMethodInvocation(BaseMethodDeclarationSyntax methodDeclarationBase, SemanticModel semanticModel, Func`2 syntaxPredicate, Func`2 symbolPredicate)
   at SonarAnalyzer.Rules.CSharp.ImplementIDisposableCorrectly.DisposableChecker.CallsVirtualDispose(BaseMethodDeclarationSyntax methodDeclaration, String argumentValue)
   at SonarAnalyzer.Rules.CSharp.ImplementIDisposableCorrectly.DisposableChecker.VerifyDisposeOverride(MethodDeclarationSyntax disposeMethod)
   at SonarAnalyzer.Rules.CSharp.ImplementIDisposableCorrectly.DisposableChecker.GetIssueLocations()
   at SonarAnalyzer.Rules.CSharp.ImplementIDisposableCorrectly.<>c.<Initialize>b__6_0(SyntaxNodeAnalysisContext c)
   at SonarAnalyzer.Helpers.DiagnosticAnalyzerContextHelper.<>c__DisplayClass0_0`1.<RegisterSyntaxNodeActionInNonGenerated>b__0(SyntaxNodeAnalysisContext c)
   at SonarAnalyzer.Helpers.SonarAnalysisContext.<>c__DisplayClass12_0`1.<RegisterSyntaxNodeAction>b__0(SyntaxNodeAnalysisContext c)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass42_1`1.<ExecuteSyntaxNodeAction>b__1()
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info)
-----
'.

@Evangelink
Copy link
Contributor

Hi @nnpcYvIVl,
thanks for this stacktrace, we will have a look tomorrow and see whether we can find what's wrong.

@Evangelink
Copy link
Contributor

Hi again @nnpcYvIVl,
The problem seems to be linked to the Redacted class which seems to be a partial implementation. I haven't find a way to reproduce the error yet. Would you mind sharing with me this class? (amaury[dot]leve[@]sonarsource[dot]com).
In case you can't share it, could you try to create reproducer based on the setup of this class (we need only the IDisposable related things like: Dispose methods, finalizers, if the class implements IDiposable, if the class is partial...

@Evangelink Evangelink modified the milestones: near-future, 6.1 Jun 21, 2017
@Evangelink Evangelink added Status: On Hold Postponed or waiting for an answer. Type: Question and removed Area: Rules Type: Bug Exceptions and blocking issues during analysis. labels Jun 23, 2017
@Evangelink Evangelink removed this from the near-future milestone Jun 23, 2017
@nnpcYvIVl
Copy link
Author

Repro code sent to your email.

@Evangelink Evangelink removed the Status: On Hold Postponed or waiting for an answer. label Jun 30, 2017
@Evangelink
Copy link
Contributor

Hi @nnpcYvIVl,

I still cannot reproduce the error with your code example. I have tried with VS2015 and VS2017. Could you tell me the exact steps using your repro case to have the issue? Also which version of the SonarLint for Visual Studio are you using?

@nnpcYvIVl
Copy link
Author

To reproduce the warning simply open the solution file and within a second or two it will show in the error list.

I'm not sure if this matters but you may want to check the following setting "Settings/Text Editor/C#/Advanced/Enable full solution analysis". It is not on by default but I normally keep it enabled.

Here is my version information:

Microsoft Visual Studio Enterprise 2017
Version 15.2 (26430.14) Release
VisualStudio.15.Release/15.2.0+26430.14
Microsoft .NET Framework
Version 4.6.01590

SonarLint for Visual Studio 3.1.1.1583

@Evangelink Evangelink added this to the 6.3 milestone Jul 13, 2017
@Evangelink Evangelink self-assigned this Jul 20, 2017
@Evangelink Evangelink added the Type: Bug Exceptions and blocking issues during analysis. label Jul 20, 2017
@Evangelink
Copy link
Contributor

@nnpcYvIVl Issue reproduced and will be fixed for next release (6.3).

Thanks for the feedback!

@nnpcYvIVl
Copy link
Author

Thanks!

@Evangelink Evangelink changed the title AD0001 ImplementIDisposableCorrectly ArgumentException Fix ImplementIDisposableCorrectly: Rule should not fail on partial classes Jul 20, 2017
@valhristov valhristov changed the title Fix ImplementIDisposableCorrectly: Rule should not fail on partial classes Fix S3881: Rule should not fail on partial classes Aug 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Exceptions and blocking issues during analysis.
Projects
None yet
Development

No branches or pull requests

4 participants