dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.02k stars 4.03k forks source link

Feature 'Semantic classification' is currently unavailable due to an internal error #67442

Closed vsfeedback closed 11 months ago

vsfeedback commented 1 year ago

This issue has been moved from a ticket on Developer Community.


Above error appears when editing code. Stack trace below.

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc. d__145`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1. d__20`1.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractEmbeddedLanguageClassificationService.AddEmbeddedLanguageClassificationsAsync(Document document, TextSpan textSpan, ClassificationOptions options, ArrayBuilder`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.AddClassificationsInCurrentProcessAsync(Document document, TextSpan textSpan, ClassificationType type, ClassificationOptions options, ArrayBuilder`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteSemanticClassificationService.<>c__DisplayClass20_0. <b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1. <g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)

Original Comments

Feedback Bot on 3/21/2023, 06:56 PM:

(private comment, text removed)

Feedback Bot on 3/22/2023, 09:59 AM:

(private comment, text removed)


Original Solutions

(no solutions)

CyrusNajmabadi commented 1 year ago

@jasonmalinowski this is a big fat 'wat' :) How can we have a Document whose SyntaxTree is not part of the very compilation of the Project that teh document belongs to. I'm guessing something very wrong with SGs. But it def seems like a core invariant that we're not allowed to break. Document.GetSemanticModelAsync should never ever throw this.

jasonmalinowski commented 1 year ago

@CyrusNajmabadi Ah yes, that's not an invariant that is expected to be broken. Hopefully we can get a crash dump for this.

jtsom commented 1 year ago

This is still an issue with Version 17.6.0 Preview 3.0:

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__20`1.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractEmbeddedLanguageClassificationService.AddEmbeddedLanguageClassificationsAsync(Document document, TextSpan textSpan, ClassificationOptions options, ArrayBuilder`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.AddClassificationsInCurrentProcessAsync(Document document, TextSpan textSpan, ClassificationType type, ClassificationOptions options, ArrayBuilder`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteSemanticClassificationService.<>c__DisplayClass20_0.<<GetClassificationsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)
CCoxshall commented 1 year ago

I'm also suffering from the same issue. New install of VS2022 17.7.0 Preview 1.0 on a new laptop. Several bars at the top stating; "Feature 'xxx' is currently unavailable due to an internal error" or "'xxx' encountered an error and has been disabled"

"Feature" stacktrace:

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__18`1.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonGetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.IsDiagnosticSuppressed(Diagnostic diagnostic, SuppressMessageInfo& info)
      at Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.ApplySourceSuppressions(Diagnostic diagnostic)
      at Microsoft.CodeAnalysis.GeneratorDriver.FilterDiagnostics(Compilation compilation, ImmutableArray`1 generatorDiagnostics, DiagnosticBag driverDiagnostics, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore(Compilation compilation, DiagnosticBag diagnosticsBag, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.GeneratorDriver.RunGenerators(Compilation compilation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.FinalizeCompilationAsync(SolutionState solution, Compilation compilationWithoutGenerators, CompilationTrackerGeneratorInfo generatorInfo, Compilation compilationWithStaleGeneratedTrees, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.BuildCompilationInfoFromScratchAsync(SolutionState solution, CompilationTrackerGeneratorInfo generatorInfo, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.BuildCompilationInfoAsync(SolutionState solution, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.GetOrBuildCompilationInfoAsync(SolutionState solution, Boolean lockGate, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.GetCompilationSlowAsync(SolutionState solution, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.InheritanceMargin.AbstractInheritanceMarginService.GetMemberSymbolsAsync(Document document, TextSpan spanToSearch, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.InheritanceMargin.AbstractInheritanceMarginService.GetInheritanceMarginItemsInProcessAsync(Document document, TextSpan spanToSearch, Boolean includeGlobalImports, Boolean frozenPartialSemantics, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.InheritanceMargin.AbstractInheritanceMarginService.GetInheritanceMemberItemsAsync(Document document, TextSpan spanToSearch, Boolean includeGlobalImports, Boolean frozenPartialSemantics, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteInheritanceMarginService.<>c__DisplayClass2_0.<<GetInheritanceMarginItemsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)

Stacktrace for the other ones:

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.Diagnostics.SuppressMessageAttributeState.IsDiagnosticSuppressed(Diagnostic diagnostic,SuppressMessageInfo& info)
   at Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.ApplySourceSuppressions(Diagnostic diagnostic)
   at Microsoft.CodeAnalysis.GeneratorDriver.FilterDiagnostics(Compilation compilation,ImmutableArray`1 generatorDiagnostics,DiagnosticBag driverDiagnostics,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore(Compilation compilation,DiagnosticBag diagnosticsBag,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.GeneratorDriver.RunGenerators(Compilation compilation,CancellationToken cancellationToken)
   at async Microsoft.CodeAnalysis.SolutionState.CompilationTracker.FinalizeCompilationAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.SolutionState.CompilationTracker.BuildCompilationInfoAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.SolutionState.CompilationTracker.GetOrBuildCompilationInfoAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.SolutionState.CompilationTracker.GetCompilationSlowAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.GenerateFromMembers.AbstractGenerateFromMembersCodeRefactoringProvider.GetSelectedMemberInfoAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.GenerateConstructorFromMembers.AbstractGenerateConstructorFromMembersCodeRefactoringProvider.GenerateConstructorFromMembersAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.GenerateConstructorFromMembers.AbstractGenerateConstructorFromMembersCodeRefactoringProvider.ComputeRefactoringsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.GetRefactoringFromProviderAsync(<Unknown Parameters>)
JeroenOortwijn commented 1 year ago

I also just got bit by this, with a slightly different stack trace:

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation
Parameter name: syntaxTree
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__20`1.MoveNext()
RPC server exception:
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.Document.<GetSemanticModelAsync>d__23.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.<GetRequiredSemanticModelAsync>d__6.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.Classification.AbstractEmbeddedLanguageClassificationService.<AddEmbeddedLanguageClassificationsAsync>d__2.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.<AddClassificationsInCurrentProcessAsync>d__7.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at Microsoft.CodeAnalysis.Remote.RemoteSemanticClassificationService.<>c__DisplayClass20_0.<<GetClassificationsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Threading.Tasks.ValueTask`1.get_Result()
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Threading.Tasks.ValueTask`1.get_Result()
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<RunWithSolutionAsync>d__9`1.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<RunWithSolutionAsync>d__9`1.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Threading.Tasks.ValueTask`1.get_Result()
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.<RunWithSolutionAsync>d__11`1.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Threading.Tasks.ValueTask`1.get_Result()
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.<RunServiceImplAsync>d__14`1.MoveNext()
Seafan75 commented 1 year ago

I too seems to have been hit with the same issue (also with the issue of several bars at the top stating; "Feature 'xxx' is currently unavailable due to an internal error" or "'xxx' encountered an error and has been disabled").

Microsoft Visual Studio Professional 2022 (64-bit) - Current Version 17.6.2

Unhandled Exception: 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.Diagnostics.SuppressMessageAttributeState.IsDiagnosticSuppressed(Diagnostic diagnostic, SuppressMessageInfo& info)

   at Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.ApplySourceSuppressions(Diagnostic diagnostic)

   at Microsoft.CodeAnalysis.GeneratorDriver.FilterDiagnostics(Compilation compilation, ImmutableArray`1 generatorDiagnostics, DiagnosticBag driverDiagnostics, CancellationToken cancellationToken)

   at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore(Compilation compilation, DiagnosticBag diagnosticsBag, CancellationToken cancellationToken)

   at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsAndUpdateCompilation(Compilation compilation, Compilation& outputCompilation, ImmutableArray`1& diagnostics, CancellationToken cancellationToken)

   at Microsoft.CodeAnalysis.CommonCompiler.RunGenerators(Compilation input, ParseOptions parseOptions, ImmutableArray`1 generators, AnalyzerConfigOptionsProvider analyzerConfigOptionsProvider, ImmutableArray`1 additionalTexts, DiagnosticBag generatorDiagnostics)

   at Microsoft.CodeAnalysis.CommonCompiler.CompileAndEmit(TouchedFileLogger touchedFilesLogger, Compilation& compilation, ImmutableArray`1 analyzers, ImmutableArray`1 generators, ImmutableArray`1 additionalTextFiles, AnalyzerConfigSet analyzerConfigSet, ImmutableArray`1 sourceFileAnalyzerConfigOptions, ImmutableArray`1 embeddedTexts, DiagnosticBag diagnostics, ErrorLogger errorLogger, CancellationToken cancellationToken, CancellationTokenSource& analyzerCts, AnalyzerDriver& analyzerDriver, Nullable`1& generatorTimingInfo)

   at Microsoft.CodeAnalysis.CommonCompiler.RunCore(TextWriter consoleOutput, ErrorLogger errorLogger, CancellationToken cancellationToken)

   at Microsoft.CodeAnalysis.CommonCompiler.Run(TextWriter consoleOutput, CancellationToken cancellationToken)

   at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.<>c__DisplayClass1_0.<Run>b__0(TextWriter tw)

   at Microsoft.CodeAnalysis.CommandLine.ConsoleUtil.RunWithUtf8Output[T](Func`2 func)

   at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.Run(String[] args, BuildPaths buildPaths, TextWriter textWriter, IAnalyzerAssemblyLoader analyzerLoader)

   at Microsoft.CodeAnalysis.CommandLine.BuildClient.RunLocalCompilation(String[] arguments, BuildPaths buildPaths, TextWriter textWriter)

   at Microsoft.CodeAnalysis.CommandLine.BuildClient.RunCompilation(IEnumerable`1 originalArguments, BuildPaths buildPaths, TextWriter textWriter, String pipeName)

   at Microsoft.CodeAnalysis.CommandLine.BuildClient.Run(IEnumerable`1 arguments, RequestLanguage language, CompileFunc compileFunc, CompileOnServerFunc compileOnServerFunc, ICompilerServerLogger logger)

   at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.MainCore(String[] args)

   at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(String[] args)
StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')

   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__18`1.MoveNext()

RPC server exception:

System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')

      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)

      at Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.IsDiagnosticSuppressed(Diagnostic diagnostic, SuppressMessageInfo& info)

      at Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.ApplySourceSuppressions(Diagnostic diagnostic)

      at Microsoft.CodeAnalysis.GeneratorDriver.FilterDiagnostics(Compilation compilation, ImmutableArray`1 generatorDiagnostics, DiagnosticBag driverDiagnostics, CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore(Compilation compilation, DiagnosticBag diagnosticsBag, CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.FinalizeCompilationAsync(SolutionState solution, Compilation compilationWithoutGenerators, CompilationTrackerGeneratorInfo generatorInfo, Compilation compilationWithStaleGeneratedTrees, CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.BuildCompilationInfoAsync(SolutionState solution, CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.GetOrBuildCompilationInfoAsync(SolutionState solution, Boolean lockGate, CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.GetCompilationSlowAsync(SolutionState solution, CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(Document document, CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.InheritanceMargin.AbstractInheritanceMarginService.GetMemberSymbolsAsync(Document document, TextSpan spanToSearch, CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.InheritanceMargin.AbstractInheritanceMarginService.GetInheritanceMarginItemsInProcessAsync(Document document, TextSpan spanToSearch, Boolean includeGlobalImports, Boolean frozenPartialSemantics, CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.InheritanceMargin.AbstractInheritanceMarginService.GetInheritanceMemberItemsAsync(Document document, TextSpan spanToSearch, Boolean includeGlobalImports, Boolean frozenPartialSemantics, CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.Remote.RemoteInheritanceMarginService.<>c__DisplayClass2_0.<<GetInheritanceMarginItemsAsync>b__0>d.MoveNext()

   --- End of stack trace from previous location ---

      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()

   --- End of stack trace from previous location ---

      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)

      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)
xchellx commented 1 year ago

Same issue.

Microsoft Visual Studio Community 2022
Version 17.6.2
VisualStudio.17.Release/17.6.2+33723.286
Microsoft .NET Framework
Version 4.8.09037

Installed Version: Community

Visual C++ 2022   00482-90000-00000-AA258
Microsoft Visual C++ 2022

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools   17.6.326.62524
ASP.NET and Web Tools

ASP.NET Web Frameworks and Tools 2012   17.6.326.62524
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   17.6.326.62524
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio   2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   17.6.326.62524
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   4.6.0-3.23259.8+c3cc1d0ceeab1a65da0217e403851a1e8a30086a
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter   17.0.23087.1
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Linux Core Dump Debugging   1.0.9.33712
Enables debugging of Linux core dumps.

Microsoft Azure Hive Query Language Service   2.6.5000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service   2.6.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio   2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Node.js Tools   1.5.50201.1 Commit Hash:0a76e2b03608f2fdee0e7d2e38e83d7721149b5f
Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager   6.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Office Developer Tools for Visual Studio   17.6.33520.00
Microsoft Office Developer Tools for Visual Studio

Python - Django support   17.0.23087.1
Provides templates and integration for the Django web framework.

Python - Profiling support   17.0.23087.1
Profiling support for Python projects.

Python with Pylance   17.0.23087.1
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Razor (ASP.NET Core)   17.6.0.2326105+37f2727000f6a964584cafb86e69cf0b39baecb7
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools   17.6.13.0
Microsoft SQL Server Data Tools

Syntax Visualizer   1.0
An extension for visualizing Roslyn SyntaxTrees.

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   17.0.20329.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.6.0-3.23259.8+c3cc1d0ceeab1a65da0217e403851a1e8a30086a
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual C++ for Linux Development   1.0.9.33712
Visual C++ for Linux Development

Visual F# Tools   17.6.0-beta.23174.5+0207bea1afae48d9351ac26fb51afc8260de0a97
Microsoft Visual F# Tools

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.
StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__20`1.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.AddSemanticClassificationsAsync(Document document, TextSpan textSpan, ClassificationOptions options, Func`2 getNodeClassifiers, Func`2 getTokenClassifiers, ArrayBuilder`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.AddClassificationsInCurrentProcessAsync(Document document, TextSpan textSpan, ClassificationType type, ClassificationOptions options, ArrayBuilder`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteSemanticClassificationService.<>c__DisplayClass20_0.<<GetClassificationsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)
sharwell commented 1 year ago

@CCoxshall @Seafan75 note that the two issues you observed are not part of this issue. I'm going to hide those two comments so we can focus on the others that are the same issue. Your issues are tracked by https://developercommunity.visualstudio.com/t/Feature-is-currently-unavailable-due-to-/10344587.

JMorrisNLP commented 1 year ago

I'm getting the same thing and it's manifesting across a ton of various features:

image

All with somewhat different stack traces but trending toward the same thing:

image image image

I've uninstalled and reinstalled various versions of VS2022, blown away various temp directories, and tried all I can think of to no avail.

Microsoft Visual Studio Professional 2022 Version 17.6.2 VisualStudio.17.Release/17.6.2+33723.286 Microsoft .NET Framework Version 4.8.09032

Installed Version: Professional

ASP.NET and Web Tools 17.6.326.62524 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.6.326.62524 Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 17.6.326.62524 Azure Functions and Web Jobs Tools

C# Tools 4.6.0-3.23259.8+c3cc1d0ceeab1a65da0217e403851a1e8a30086a C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager 6.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core) 17.6.0.2326105+37f2727000f6a964584cafb86e69cf0b39baecb7 Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.6.13.0 Microsoft SQL Server Data Tools

TypeScript Tools 17.0.20329.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.6.0-3.23259.8+c3cc1d0ceeab1a65da0217e403851a1e8a30086a Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.6.0-beta.23174.5+0207bea1afae48d9351ac26fb51afc8260de0a97 Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

sharwell commented 1 year ago

@JMorrisNLP note that the issue you observed is not part of this issue. I'm going to hide the comment so we can focus on the others that are the same issue. Your issue is tracked by https://developercommunity.visualstudio.com/t/Feature-is-currently-unavailable-due-to-/10344587.

JMorrisNLP commented 1 year ago

Ok thank you. I struggled to find the most appropriate place for this as I see a lot of really close reports.

kindermannhubert commented 1 year ago

Here's another call stack with SyntaxTree is not part of the compilation (Parameter 'syntaxTree') I've run into:

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__21.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.DesignerAttribute.DesignerAttributeDiscoveryService.ComputeDesignerAttributeCategoryAsync(Boolean hasDesignerCategoryType, Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.DesignerAttribute.DesignerAttributeDiscoveryService.<>c__DisplayClass9_0.<<ComputeChangedDataAsync>g__ComputeDesignerAttributeDataAsync|0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.DesignerAttribute.DesignerAttributeDiscoveryService.ComputeChangedDataAsync(Project project, Document specificDocument, AsyncLazy`1 lazyProjectVersion, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.DesignerAttribute.DesignerAttributeDiscoveryService.ScanForDesignerCategoryUsageAsync(Project project, Document specificDocument, ICallback callback, AsyncLazy`1 lazyProjectVersion, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.DesignerAttribute.DesignerAttributeDiscoveryService.ProcessProjectAsync(Project project, Document specificDocument, Boolean useFrozenSnapshots, ICallback callback, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.DesignerAttribute.DesignerAttributeDiscoveryService.ProcessSolutionAsync(Solution solution, DocumentId priorityDocumentId, Boolean useFrozenSnapshots, ICallback callback, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.<>c__DisplayClass16_0.<<RunServiceAsync>b__1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.<>c__DisplayClass16_0.<<RunServiceAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync(Func`2 implementation, CancellationToken cancellationToken)

VS 17.6.1

jtsom commented 1 year ago

STILL an issue in Version 17.7.0 Preview 1

Pretty much anytime I edit ANY code, this pops up.

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__20`1.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.AddSemanticClassificationsAsync(Document document, TextSpan textSpan, ClassificationOptions options, Func`2 getNodeClassifiers, Func`2 getTokenClassifiers, SegmentedList`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.AddClassificationsInCurrentProcessAsync(Document document, TextSpan textSpan, ClassificationType type, ClassificationOptions options, SegmentedList`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteSemanticClassificationService.<>c__DisplayClass20_0.<<GetClassificationsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)
CyrusNajmabadi commented 1 year ago

@jtsom can you give us a link to your repro project? Thanks!

jtsom commented 1 year ago

Unfortunately, it's my company's application, and the code is not openly available. It's a ASP.NET application (.NET Framework 4.8)

JMorrisNLP commented 1 year ago

@CyrusNajmabadi, I'm having similar (if not the same) experience as @jtsom. The repo doesn't matter. In my experience, I can start from a completely new dotnet new console project and as soon as I start VS, all my feature sets start to collapse citing the same syntaxTree error. The only thing that changes is the stack info as it tends to pertain to the VS feature that's failing.

CyrusNajmabadi commented 1 year ago

Can you put a copy of that project on GitHub and link is to it? I am not reproing this with those steps. I'm curious if something is different here.

jasonmalinowski commented 1 year ago

I've got a crash dump internally through our error reporting channels I'm looking at. @CyrusNajmabadi turns out the one case is not a source generated file which does not make me feel any better, but...

jasonmalinowski commented 1 year ago

Alright so the one internal crash dump showed the following:

  1. The solution had a single project.
  2. The document object had one syntax tree, but the Compilation produced had a different syntax tree (but a tree did exist with the same filename.)
  3. The source file was open.
  4. The two trees in question had the same text (by object identity) of the same editor snapshot and same options (also by identity.)

Therea are no hits for 17.5.* versions, which makes me think this is something related to our work to link syntax trees and try to better reuse them that shipped in 17.6. There is a feature flag we can throw which will disable that, but since that work had significant perf wins I hesitate to just throw that without a bit more work to investigate. I've looked through the code and don't see anything jumping out. We've also got some error reporting hits for some exceptions being thrown in the code that is trying to unify the trees which also seems suspicious, so I've requested dumps for that and we'll see if that reveals any problems there that might also explain this too.

CyrusNajmabadi commented 1 year ago

Note: we don't share syntax trees. We share the green nodes. The trees are still separate instances.

jasonmalinowski commented 1 year ago

@CyrusNajmabadi Yep, my only guess though something in that work somehow broke this. (Not obvious how though...)

CyrusNajmabadi commented 1 year ago

Could we have screwed up the compilation tracker such that it's picking the wrong tree to make the compilation with?

jasonmalinowski commented 1 year ago

@CyrusNajmabadi Presumably that's what we did (somewhere.)

toresenneseth commented 1 year ago

Hi, looks like you have already started tracking down the issue. If it helps, I can confirm that I (and my entire team) had no issues in 17.5, but get this error consistently in 17.6

Here's my stack trace (happens every time I try to rename a variable, class, etc).

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__22`1.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonGetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.IsDiagnosticSuppressed(Diagnostic diagnostic, SuppressMessageInfo& info)
      at Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.ApplySourceSuppressions(Diagnostic diagnostic)
      at Microsoft.CodeAnalysis.GeneratorDriver.FilterDiagnostics(Compilation compilation, ImmutableArray`1 generatorDiagnostics, DiagnosticBag driverDiagnostics, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore(Compilation compilation, DiagnosticBag diagnosticsBag, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.GeneratorDriver.RunGenerators(Compilation compilation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.FinalizeCompilationAsync(SolutionState solution, Compilation compilationWithoutGenerators, CompilationTrackerGeneratorInfo generatorInfo, Compilation compilationWithStaleGeneratedTrees, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.BuildCompilationInfoFromScratchAsync(SolutionState solution, CompilationTrackerGeneratorInfo generatorInfo, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.BuildCompilationInfoAsync(SolutionState solution, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.GetOrBuildCompilationInfoAsync(SolutionState solution, Boolean lockGate, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.GetSourceGeneratedDocumentStatesAsync(SolutionState solution, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Project.GetSourceGeneratedDocumentsAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Project.GetAllRegularAndSourceGeneratedDocumentsAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.Finders.AbstractReferenceFinder`1.GetAllMatchingGlobalAliasNamesAsync(Project project, String name, Int32 arity, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.AddGlobalAliasesAsync(Project project, ImmutableArray`1 allSymbols, PooledDictionary`2 symbolToGlobalAliases, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessProjectAsync(Project project, ImmutableArray`1 allSymbols, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessProjectAsync(Project project, ImmutableArray`1 allSymbols, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.FindRenamableReferencesAsync(ImmutableArray`1 symbols, Solution solution, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Rename.SymbolicRenameLocations.AddLocationsReferenceSymbolsAsync(ISymbol symbol, Solution solution, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Rename.SymbolicRenameLocations.FindLocationsInCurrentProcessAsync(ISymbol symbol, Solution solution, SymbolRenameOptions options, CodeCleanupOptionsProvider cleanupOptions, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Rename.Renamer.RenameSymbolInCurrentProcessAsync(Solution solution, ISymbol symbol, String newName, SymbolRenameOptions options, CodeCleanupOptionsProvider cleanupOptions, ImmutableArray`1 nonConflictSymbolKeys, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Rename.Renamer.RenameSymbolAsync(Solution solution, ISymbol symbol, String newName, SymbolRenameOptions options, CodeCleanupOptionsProvider fallbackOptions, ImmutableArray`1 nonConflictSymbolKeys, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteRenamerService.<>c__DisplayClass4_0.<<RenameSymbolAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)
toresenneseth commented 1 year ago

So I noticed that this happened in one of our solutions, and not in another. The solution with the issue is using source generators heavily, while the other is not. I updated all Roslyn NuGet packages from 4.4 and 4.5 to 4.6 in the solution that was using source generators, and the problem went away.

This is just my observations. Not sure if NuGet version mismatches are actually causing this in some way, but it might be an extra clue.

jasonmalinowski commented 1 year ago

@toresenneseth: the stack you did hit is indeed related to source generators and that one's being investigated by @chsienki. The package versions don't really matter since when you are being loaded you're using the version that actually ships with VS, but there's some timing bugs here that means it won't impact all scenarios all the time.

RoseFlunder commented 1 year ago

Here's another call stack with SyntaxTree is not part of the compilation (Parameter 'syntaxTree') I've run into:

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__21.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.DesignerAttribute.DesignerAttributeDiscoveryService.ComputeDesignerAttributeCategoryAsync(Boolean hasDesignerCategoryType, Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.DesignerAttribute.DesignerAttributeDiscoveryService.<>c__DisplayClass9_0.<<ComputeChangedDataAsync>g__ComputeDesignerAttributeDataAsync|0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.DesignerAttribute.DesignerAttributeDiscoveryService.ComputeChangedDataAsync(Project project, Document specificDocument, AsyncLazy`1 lazyProjectVersion, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.DesignerAttribute.DesignerAttributeDiscoveryService.ScanForDesignerCategoryUsageAsync(Project project, Document specificDocument, ICallback callback, AsyncLazy`1 lazyProjectVersion, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.DesignerAttribute.DesignerAttributeDiscoveryService.ProcessProjectAsync(Project project, Document specificDocument, Boolean useFrozenSnapshots, ICallback callback, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.DesignerAttribute.DesignerAttributeDiscoveryService.ProcessSolutionAsync(Solution solution, DocumentId priorityDocumentId, Boolean useFrozenSnapshots, ICallback callback, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.<>c__DisplayClass16_0.<<RunServiceAsync>b__1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.<>c__DisplayClass16_0.<<RunServiceAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync(Func`2 implementation, CancellationToken cancellationToken)

VS 17.6.1

I got the same stack trace with VS 17.6.3

realparadyne commented 1 year ago

I'm getting it on 17.7.0 Preview 2.0

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__20`1.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractEmbeddedLanguageClassificationService.AddEmbeddedLanguageClassificationsAsync(Document document, TextSpan textSpan, ClassificationOptions options, SegmentedList`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.AddClassificationsInCurrentProcessAsync(Document document, TextSpan textSpan, ClassificationType type, ClassificationOptions options, SegmentedList`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteSemanticClassificationService.<>c__DisplayClass20_0.<<GetClassificationsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)

`Microsoft Visual Studio Professional 2022 Version 17.7.0 Preview 2.0 VisualStudio.17.Preview/17.7.0-pre.2.0+33808.371 Microsoft .NET Framework Version 4.8.09032

Installed Version: Professional

Visual C++ 2022 00483-10050-13494-AA209 Microsoft Visual C++ 2022

ASP.NET and Web Tools 17.7.160.18752 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.7.160.18752 Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 17.7.160.18752 Azure Functions and Web Jobs Tools

C# Tools 4.7.0-2.23280.4+66772aff549b2981094175a6f2f69600596c1913 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter 17.0.23150.1 Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Developer News 2022 1.0.83 Always stay up to date with developer news from the Visual Studio team and other sources right within Visual Studio or your default browser.

F# Formatting 1.0 F# source code formatting using Fantomas.

File Icons 2.7 Adds icons for files that are not recognized by Solution Explorer

Font Sizer 2.0 1.0.9 An easy way to change the font sizes in the editor and Visual Studio environment.

Insert Guid 1.3.6 Makes it super easy to insert a new GUID into any editor and input field

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager 6.7.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Python - Profiling support 17.0.23150.1 Profiling support for Python projects.

Python with Pylance 17.0.23150.1 Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Razor (ASP.NET Core) 17.7.2.2330502+e0cf0b1121019f24d79b73d6d30f5870ca83c81d Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.7.1.0 Microsoft SQL Server Data Tools

Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

Tweaks 2022 1.1.143 A collection of minor fixes and tweaks for Visual Studio to reduce the paper cuts and make you a happier developer

TypeScript Tools 17.0.20531.2001 TypeScript Tools for Microsoft Visual Studio

Viasfora 4.4.212 Add color to your Visual Studio editor!

Visual Basic Tools 4.7.0-2.23280.4+66772aff549b2981094175a6f2f69600596c1913 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.7.0-beta.23272.3+96bfa24a5fee6722ed3e2b280d37e80b594bbcf4 Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.`

I'm working on an old .Net Framework solution that completely predates source generators.

Matthias-Heinz commented 1 year ago

The issue still persist in Visual Studio 2022 (v.17.6.5). C.f. my original report.

Assuming the issue comes up again, is there anything I can help you with to troubleshoot the error?

CyrusNajmabadi commented 1 year ago

A repro project and repro case would be great!

Uladzimir-Lashkevich commented 1 year ago

Hi, guys! When we can expect this to be fixed? I saw comment that it will be fixed in 17.6.6 somewhere in vs feedback site, but cannot find it anymore. This issue blocks work on a version of VS >= 17.6.0

My stacktrace

```charp StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree') at StreamJsonRpc.JsonRpc.d__151`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.d__18`1.MoveNext() RPC server exception: System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree') at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility) at Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.IsDiagnosticSuppressed(Diagnostic diagnostic, SuppressMessageInfo& info) at Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.ApplySourceSuppressions(Diagnostic diagnostic) at Microsoft.CodeAnalysis.GeneratorDriver.FilterDiagnostics(Compilation compilation, ImmutableArray`1 generatorDiagnostics, DiagnosticBag driverDiagnostics, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore(Compilation compilation, DiagnosticBag diagnosticsBag, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.FinalizeCompilationAsync(SolutionState solution, Compilation compilationWithoutGenerators, CompilationTrackerGeneratorInfo generatorInfo, Compilation compilationWithStaleGeneratedTrees, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.BuildCompilationInfoAsync(SolutionState solution, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.GetOrBuildCompilationInfoAsync(SolutionState solution, Boolean lockGate, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.GetSourceGeneratedDocumentStatesAsync(SolutionState solution, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Project.GetSourceGeneratedDocumentsAsync(CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Project.GetAllRegularAndSourceGeneratedDocumentsAsync(CancellationToken cancellationToken) at Microsoft.CodeAnalysis.FindSymbols.Finders.AbstractReferenceFinder.FindDocumentsAsync[T](Project project, IImmutableSet`1 scope, Func`4 predicateAsync, T value, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.FindSymbols.Finders.OrdinaryMethodReferenceFinder.DetermineDocumentsToSearchAsync(IMethodSymbol methodSymbol, HashSet`1 globalAliases, Project project, IImmutableSet`1 documents, FindReferencesSearchOptions options, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessProjectAsync(Project project, ImmutableArray`1 allSymbols, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessProjectAsync(Project project, ImmutableArray`1 allSymbols, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.FindReferencesAsync(ISymbol symbol, Solution solution, IStreamingFindReferencesProgress progress, IImmutableSet`1 documents, FindReferencesSearchOptions options, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.FindReferencesAsync(ISymbol symbol, Solution solution, IFindReferencesProgress progress, IImmutableSet`1 documents, FindReferencesSearchOptions options, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.CodeLens.CodeLensReferencesService.FindAsync[T](Solution solution, DocumentId documentId, SyntaxNode syntaxNode, Func`2 onResults, Func`2 onCapped, Int32 searchCap, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.CodeLens.CodeLensReferencesService.GetReferenceCountAsync(Solution solution, DocumentId documentId, SyntaxNode syntaxNode, Int32 maxSearchResults, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Remote.RemoteCodeLensReferencesService.<>c__DisplayClass3_0.<b__0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<g__ProcessSolutionAsync|1>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Remote.RemoteCodeLensReferencesService.GetReferenceCountAsync(Checksum solutionChecksum, DocumentId documentId, TextSpan textSpan, Int32 maxResultCount, CancellationToken cancellationToken) ```

jasonmalinowski commented 1 year ago

@Uladzimir-Lashkevich The fix is scheduled for 17.6.6 but looking at our internal schedule that's a bit further out than I would have thought. Let me ask around internally.

trinare commented 1 year ago

I'm having the same problem in 17.7. Here's the stack trace.

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__20`1.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractEmbeddedLanguageClassificationService.AddEmbeddedLanguageClassificationsAsync(Document document, TextSpan textSpan, ClassificationOptions options, SegmentedList`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.AddClassificationsInCurrentProcessAsync(Document document, TextSpan textSpan, ClassificationType type, ClassificationOptions options, SegmentedList`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteSemanticClassificationService.<>c__DisplayClass20_0.<<GetClassificationsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)
jasonmalinowski commented 1 year ago

Just a status update for everyone: the fix for the variant of this that contains "SuppressMessageAttributeState.IsDiagnosticSuppressed" is out in 17.6.6 and 17.7.0. The other variant is still (unfortunately) under investigation, but we've got some new logging in 17.7 to help track that down.

planetarian commented 1 year ago

same issue happening very frequently in 17.7.1

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__20`1.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.AddSemanticClassificationsAsync(Document document, TextSpan textSpan, ClassificationOptions options, Func`2 getNodeClassifiers, Func`2 getTokenClassifiers, SegmentedList`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.AddClassificationsInCurrentProcessAsync(Document document, TextSpan textSpan, ClassificationType type, ClassificationOptions options, SegmentedList`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteSemanticClassificationService.<>c__DisplayClass20_0.<<GetClassificationsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)
sharwell commented 1 year ago

@planetarian if you disable (uncheck) the following option, does the problem still occur? image

rolflinke commented 1 year ago

@sharwell: Thanks! This workaround works for me.

regisbsb commented 1 year ago

17.7.4 while typing a switch expression

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__20`1.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.AddSemanticClassificationsAsync(Document document, TextSpan textSpan, ClassificationOptions options, Func`2 getNodeClassifiers, Func`2 getTokenClassifiers, SegmentedList`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.AddClassificationsInCurrentProcessAsync(Document document, TextSpan textSpan, ClassificationType type, ClassificationOptions options, SegmentedList`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteSemanticClassificationService.<>c__DisplayClass20_0.<<GetClassificationsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)
PondPackMan2023 commented 1 year ago

I'm currently on VS2022 17.7.5 and still get this issue.

The only pattern I've noticed is that you need to reference the MIcrosoft.Build NuGet package. It seems related to this NuGet package and the project being a console project. I am targeting net7.0-windows.

Hopefully that is helpful to someone.

jasonmalinowski commented 11 months ago

Just to give a bit of a status update here: we've been trying to track this down for awhile now, eventually adding some extra tracing in https://github.com/dotnet/roslyn/pull/70347 to 17.7.6 which we enabled via remote feature flag earlier this week. We've been somewhat cautious here as that logging could potentially make some algorithms we have go from O(n) to O(n^2) so folks with really big projects might have been impacted.

We now have one memory dump from the new logging, so I can at least confirm a few things (and FYI to @CyrusNajmabadi and @arkalyanms):

  1. The path creating the mismatch is frozen partial semantics.
  2. The project that had a mismatch does not have source generators at all, and the tree involved is not from a source generator.
  3. It appears the syntax tree that mismatched between the Compilation and ProjectState is the original document that was being frozen in the first place.
  4. Before the validation triggered, we would have ran this assertion which if it passed indicates the problem isn't the tree not matching the compilation, but rather the in-progress project state not having the expected DocumentState. So either I'm guessing GetPartialCompilationState didn't return what we expected, or one of the updates to inProgress state in this section of code either was skipped or didn't do what we wanted.

My hunch at this point is this was either regressed with a change like https://github.com/dotnet/roslyn/pull/65349 (although the timing doesn't match up there), or simply that as we have moved more features to asking for partial semantics due to source generator performance mitigation, we've exposed some long hiding bug around here.

Unfortunately I'm running into a few debugger issues which is making this hard to analyze the dump further, so I'm reaching out to the debugger team for assistance while I also have to unblock some other work at the moment.

jasonmalinowski commented 11 months ago

As far as people trying to figure out causes: this won't depend on your specific projects. For example, this won't impact projects only referencing certain NuGet packages or specific code patterns. I'd imagine it will depend more on your machine performance or simply project scale as that might make it more or less likely to hit the specific race condition being hit here.

CyrusNajmabadi commented 11 months ago

@jasonmalinowski we may want to go back to first principles in terms of what we want for "frozen partial". A new implementation that then follows those principles, but behaves well wrt our modern understanding of SGs might be necessary.

jasonmalinowski commented 11 months ago

We've identified a very subtle bug in a synchronization primitive we were using that we think is causing this, so we're hoping to have this patched in 17.8.1 (or maybe 17.8.2 if we miss that internal cutoff, not sure yet as of this writing.) Once that's in and we're seeing telemetry data confirming we do in fact have the fix, we'll then look at what backporting we may need to do to older releases like 17.6.

Since some workarounds have been proposed here: this is a race in a deep piece of code that has nothing to do with the structure of your project. Turning off out-of-process analysis probably won't stop it, although maybe it impacts timing in some way that might make it harder to hit, but that's largely luck.

PondPackMan2023 commented 11 months ago

@jasonmalinowski Thank you for looking into this. I can only image the difficulties involved. I look forward to the fix, whenever that might be.

jasonmalinowski commented 11 months ago

More importantly, thanks for the patience! The PR has a writeup if people are curious, but fundamentally this a race condition in a synchronization primitive we use, and the bug in that code has been there for over 10 years. But for various reasons it didn't matter since either that path wasn't executed often, or if it was other code that used the primitive used it in a way that the bug didn't matter. Until a set entirely unrelated changes probably meant it's now been bad.

My biggest worry of course is if there's a second bug lurking...

jasonmalinowski commented 11 months ago

Just a small update here: we did miss the cutoff for 17.8.1, so 17.8.2 it'll be.

jasonmalinowski commented 11 months ago

17.8.2 is now out, so closing this as fixed. If anybody still sees this on 17.8.2 do let me know, since we can't rule out a second bug here somewhere.

teaminvise commented 11 months ago

@jasonmalinowski We've been running 17.9.0 Preview 1 hoping that the fix was part of this release, and the issue has not been resolved. Was there a patch released in 17.8.2 that is not included in the original 17.9.0 Preview 1 version? If no, then this should not be closed, because the issue still exists in 17.9.0 Preview 1.

To try to resolve this problem, we have tried a number of things, including uninstalling all Visual Studio installations and installed the latest preview. This has been ongoing this entire year, and as recently as yesterday on 17.9.0 Preview 1, components continue to crash. The other problem we've been having is that at the same time of these "currently unavailable" gold bar messages, the scrolling and intellicode typing gets really laggy and really slow. When this happens, using Visual Studio is pretty much impossible. To fix the problem, we have to save and close all projects, exit Visual Studio completely, and then reopen the projects we are working on. Sometimes we even have to reboot the affected machine, or pretty much the instant that Visual Studio is reopened and you start typing, the "currently unavailable" message reappears. Very much a pain in the arse.

cc @mnlierman ~Jake H.

CyrusNajmabadi commented 11 months ago

@teaminvise what are the stack traces in the notification messages you are seeing?

teaminvise commented 11 months ago

@teaminvise what are the stack traces in the notification messages you are seeing?

It's the exact same! If you use an online text compare tool and compare the pasted Stack Trace above with mine below, it's exactly the same, with the exception of this piece "document, ImmutableArray`1 textSpans"

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__20`1.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, Boolean ignoreAccessibility)
      at Microsoft.CodeAnalysis.Document.GetSemanticModelAsync(CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetRequiredSemanticModelAsync(Document document, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.AddSemanticClassificationsAsync(Document document, ImmutableArray`1 textSpans, ClassificationOptions options, Func`2 getNodeClassifiers, Func`2 getTokenClassifiers, SegmentedList`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.AddClassificationsInCurrentProcessAsync(Document document, ImmutableArray`1 textSpans, ClassificationType type, ClassificationOptions options, SegmentedList`1 result, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteSemanticClassificationService.<>c__DisplayClass20_0.<<GetClassificationsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)