Skip to content

Commit fcc9f38

Browse files
CopilotYunchuWang
andcommitted
Fix SyntaxTree is not part of the compilation exception in analyzers
Co-authored-by: YunchuWang <[email protected]>
1 parent 6ec4d4b commit fcc9f38

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Analyzers/Orchestration/OrchestrationAnalyzer.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,15 @@ void FindInvokedMethods(
330330
{
331331
// Since the syntax tree of the callee method might be different from the caller method, we need to get the correct semantic model,
332332
// avoiding the exception 'Syntax node is not within syntax tree'.
333+
// We also need to check if the syntax tree is part of the compilation to avoid 'SyntaxTree is not part of the compilation' exception.
334+
if (!this.Compilation.ContainsSyntaxTree(calleeSyntax.SyntaxTree))
335+
{
336+
// Skip this syntax tree if it's not part of the compilation (e.g., from external assemblies)
337+
continue;
338+
}
339+
333340
SemanticModel sm = semanticModel.SyntaxTree == calleeSyntax.SyntaxTree ?
334-
semanticModel : semanticModel.Compilation.GetSemanticModel(calleeSyntax.SyntaxTree);
341+
semanticModel : this.Compilation.GetSemanticModel(calleeSyntax.SyntaxTree);
335342

336343
this.FindInvokedMethods(sm, calleeSyntax, calleeMethodSymbol, rootOrchestration, reportDiagnostic);
337344
}

0 commit comments

Comments
 (0)