Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 21, 2025

Analyzers threw ArgumentException: SyntaxTree is not part of the compilation when analyzing orchestration methods that invoke methods from referenced projects. Affects DURABLE0001-DURABLE0006, DURABLE0009-DURABLE0010.

Root cause

MethodProbeOrchestrationVisitor.FindInvokedMethods() used semanticModel.Compilation to get semantic models for invoked methods. When those methods exist in different syntax trees (e.g., referenced projects), the syntax tree isn't part of that compilation instance.

Changes

In OrchestrationAnalyzer.cs, modified FindInvokedMethods():

  • Use this.Compilation instead of semanticModel.Compilation when obtaining semantic models for callee syntax trees
  • Skip syntax trees not in the current compilation context via ContainsSyntaxTree() check
// Before
SemanticModel sm = semanticModel.SyntaxTree == calleeSyntax.SyntaxTree ?
    semanticModel : semanticModel.Compilation.GetSemanticModel(calleeSyntax.SyntaxTree);

// After
if (!this.Compilation.ContainsSyntaxTree(calleeSyntax.SyntaxTree))
{
    continue;
}

SemanticModel sm = semanticModel.SyntaxTree == calleeSyntax.SyntaxTree ?
    semanticModel : this.Compilation.GetSemanticModel(calleeSyntax.SyntaxTree);

this.Compilation is the full compilation context containing all syntax trees being analyzed, while semanticModel.Compilation may only contain a subset.

Original prompt

This section details on the original issue you should resolve

<issue_title>Analyzers throw "SyntaxTree is not part of the compilation" exceptions</issue_title>
<issue_description>I cannot get the following 6 warnings to go away when running code analysis on this project using DurableTask.

Analyzer 'Microsoft.DurableTask.Analyzers.Orchestration.DateTimeOrchestrationAnalyzer' threw an exception of type 'System.ArgumentException' with message 'SyntaxTree is not part of the compilation (Parameter 'syntaxTree')'.
Exception occurred with following context:
Compilation: <Project Name>
SyntaxTree: C:\Users\abryden\git\<project path>\TaskDispatcher.cs
SyntaxNode: [Function(nameof(OrchestrateDispatch ... [MethodDeclarationSyntax]@[2335..3145) (66,4)-(80,5)

System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, SemanticModelOptions options)
   at Microsoft.DurableTask.Analyzers.Orchestration.MethodProbeOrchestrationVisitor.FindInvokedMethods(SemanticModel semanticModel, SyntaxNode callerSyntax, IMethodSymbol callerSymbol, String rootOrchestration, Action`1 reportDiagnostic)
   at Microsoft.DurableTask.Analyzers.Orchestration.OrchestrationAnalyzer`1.<>c__DisplayClass0_0.<Initialize>b__1(SyntaxNodeAnalysisContext ctx)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)
-----

Suppress the following diagnostics to disable this analyzer: DURABLE0001

I get one of these for each of DURABLE0001, DURABLE0002, DURABLE0003, DURABLE0004, DURABLE0005, DURABLE0006 - each the same except for the Analyzer name at the start of the message. My colleagues see the same on their own machines.

IDE: Microsoft Visual Studio Professional 2022 (64-bit) - Current - Version 17.14.21 (November 2025)

I've tried things like restarting, reinstalling the latest VS2022, removing and re-adding the nuget package Microsoft.Azure.Functions.Worker.Extensions.DurableTask, explicitly installing the Microsoft.DurableTask.Analyzers package (there's only version 0.1.0, so I can't test upgrading/downgrading this).

I've searched and found similar issues to "SyntaxTree is not part of the compilation" seemingly resolved by visual studio updates (e.g. https://developercommunity.visualstudio.com/t/Feature-Semantic-classification-is-cur/10370922), as well as previously fixed Analyzer issues (e.g. Azure/azure-functions-durable-extension#1320), so perhaps this is a new issue in a similar vein?

Thanks for your help, and sorry if this turns out not to be an issue related to this project.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix analyzers throwing syntax tree exception Fix "SyntaxTree is not part of the compilation" exception in orchestration analyzers Dec 21, 2025
Copilot AI requested a review from YunchuWang December 21, 2025 21:13
@YunchuWang YunchuWang marked this pull request as ready for review December 22, 2025 23:08
Copilot AI review requested due to automatic review settings December 22, 2025 23:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where Roslyn analyzers DURABLE0001-DURABLE0006, DURABLE0009-DURABLE0010 threw ArgumentException: SyntaxTree is not part of the compilation when analyzing orchestration methods that invoke methods from referenced projects.

Key Changes

  • Modified FindInvokedMethods() in MethodProbeOrchestrationVisitor to check if syntax trees are part of the compilation context before attempting to get their semantic models
  • Changed from using semanticModel.Compilation to this.Compilation to access the full compilation context containing all syntax trees being analyzed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analyzers throw "SyntaxTree is not part of the compilation" exceptions

2 participants