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

Analyzer 'NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.ReEntrantSetupAnalyzer' threw an exception of type 'System.ArgumentException' with message 'SyntaxTree is not part of the compilation' #56

Closed
meziantou opened this issue Dec 4, 2018 · 5 comments · Fixed by #58
Assignees
Labels
bug Something isn't working
Milestone

Comments

@meziantou
Copy link

Hi,
I got this exception on my project:

Severity	Code	Description	Project	File	Line	Suppression State	Detail Description
Warning	AD0001	Analyzer 'NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.ReEntrantSetupAnalyzer' threw an exception of type 'System.ArgumentException' with message 'SyntaxTree is not part of the compilation
Parameter name: syntaxTree'.	*****		1	Active	Analyzer 'NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.ReEntrantSetupAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: *****
SyntaxTree: C:\Users\Tests.cs
SyntaxNode: preferenceCollection.Get(@"t:\a.csproj" ... [InvocationExpressionSyntax]@[474..540) (15,12)-(15,78)

System.ArgumentException: SyntaxTree is not part of the compilation
Parameter name: syntaxTree
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonGetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
   at NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.ReEntrantCallFinder.ReEntrantCallVisitor.VisitInvocationExpression(InvocationExpressionSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.DefaultVisit(SyntaxNode node)
   at NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.ReEntrantCallFinder.ReEntrantCallVisitor.DefaultVisit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitArrowExpressionClause(ArrowExpressionClauseSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.ArrowExpressionClauseSyntax.Accept(CSharpSyntaxVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.DefaultVisit(SyntaxNode node)
   at NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.ReEntrantCallFinder.ReEntrantCallVisitor.DefaultVisit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitAccessorDeclaration(AccessorDeclarationSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.AccessorDeclarationSyntax.Accept(CSharpSyntaxVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.DefaultVisit(SyntaxNode node)
   at NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.ReEntrantCallFinder.ReEntrantCallVisitor.DefaultVisit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitAccessorList(AccessorListSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.AccessorListSyntax.Accept(CSharpSyntaxVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.DefaultVisit(SyntaxNode node)
   at NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.ReEntrantCallFinder.ReEntrantCallVisitor.DefaultVisit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitPropertyDeclaration(PropertyDeclarationSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.PropertyDeclarationSyntax.Accept(CSharpSyntaxVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.DefaultVisit(SyntaxNode node)
   at NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.ReEntrantCallFinder.ReEntrantCallVisitor.DefaultVisit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitClassDeclaration(ClassDeclarationSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax.Accept(CSharpSyntaxVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.Visit(SyntaxNode node)
   at NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.ReEntrantCallFinder.ReEntrantCallVisitor.VisitRelatedSymbols(SyntaxNode syntaxNode)
   at NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.ReEntrantCallFinder.ReEntrantCallVisitor.DefaultVisit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitIdentifierName(IdentifierNameSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.IdentifierNameSyntax.Accept(CSharpSyntaxVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.DefaultVisit(SyntaxNode node)
   at NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.ReEntrantCallFinder.ReEntrantCallVisitor.DefaultVisit(SyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitObjectCreationExpression(ObjectCreationExpressionSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.ObjectCreationExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.Visit(SyntaxNode node)
   at NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers.ReEntrantCallFinder.GetReEntrantSymbols(Compilation compilation, SyntaxNode rootNode)
   at NSubstitute.Analyzers.Shared.DiagnosticAnalyzers.AbstractReEntrantCallFinder.GetReEntrantCalls(Compilation compilation, SyntaxNode rootNode)
   at NSubstitute.Analyzers.Shared.DiagnosticAnalyzers.AbstractReEntrantSetupAnalyzer`2.AnalyzeInvocation(SyntaxNodeAnalysisContext syntaxNodeContext)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__44`1.<ExecuteSyntaxNodeAction>b__44_0(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
@tpodolak
Copy link
Member

tpodolak commented Dec 4, 2018

Hi,
Thanks for reporting. We had similar issue some time ago #46, we thought we fixed it, but apperently there is another way of reproducing it. Is there any chance you could share sample project to reproduce this one? Having that I would be able to add proper integration tests otherwise I will have to fix it "blindly"

@meziantou
Copy link
Author

Hi,

Sorry for the delay. My project is private, so I cannot share it with you. I tried to create a repro project without success.

I also tried to clone the repository and start the NSubstitute.Analyzers.CSharp.Vsix project to debug the problem on my side. However, it seems the extension is not loaded. What's the easiest way to debug a solution?

Thanks

@tpodolak
Copy link
Member

@meziantou vsix was supposed to be the easiest way to debug analyzers. I tested this on some older Visual Studio instances and it worked as expected. However I ve never had a chance to test it on the newer versions as I dont have a license. One way or another, I will provide the fix for this bug once I am back from my holidays(I think I know where the problem is, even though I cannot repro it)

@tpodolak
Copy link
Member

tpodolak commented Jan 3, 2019

Released in 1.0.4

@meziantou
Copy link
Author

Thank you very much for fixing this issue. It now works great on my project!

@tpodolak tpodolak added this to the 1.0.4 milestone Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants