Skip to content

When source files generated by ISourceGenerator and IIncrementalGenerator are removed "Inheritance margin" and "CodeLens references" features crash #77357

@pheonick

Description

@pheonick

Version Used:

  • .NET SDK Version: 9.0.200
  • Microsoft.CodeAnalysis.Analyzers Version: 3.11.0
  • Microsoft.CodeAnalysis.CSharp Version: 4.13.0

Steps to Reproduce:

  1. Have a source/incremental generator generate a source file
  2. Make a change that would force the generator to remove the source file

For example:
I've created this test repository https://github.com/pheonick/GeneratorProject
Steps to reproduce here:

  1. Build UserProject.csproj
  2. Close solution
  3. Open solution so that the IIncrementalGenerator loads to ServiceHub.RoslynCodeAnalysisService process
  4. Open UserProject/UserClass.cs
  5. Remove lines with 5-7, the [Test(...)] attributes
  6. Save UserProject/UserClass.cs file, which should start a generation process that would remove the UserProject.UserClass.g.cs file

Expected Behavior:
Source file is removed and generation passes successfully.

Actual Behavior:

  • "Inheritance margin" feature fails with the following code stack:
StreamJsonRpc.RemoteInvocationException: The solution does not contain the specified document.
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__156`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.InvalidOperationException: The solution does not contain the specified document.
      at Microsoft.CodeAnalysis.Shared.Extensions.ISolutionExtensions.GetRequiredDocumentAsync(Solution solution, DocumentId documentId, Boolean includeSourceGenerated, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.<>c__DisplayClass6_1.<<DescendInheritanceTreeAsync>g__GetRequiredSemanticModelAsync|4>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.<>c__DisplayClass6_1.<<DescendInheritanceTreeAsync>g__AddSourceTypesThatDeriveFromNameAsync|6>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.<>c__DisplayClass6_0.<<DescendInheritanceTreeAsync>g__AddDescendantSourceTypesInProjectAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.<>c__DisplayClass6_0.<<DescendInheritanceTreeAsync>g__DescendInheritanceTreeInProjectAsync|0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.DescendInheritanceTreeAsync(INamedTypeSymbol type, Solution solution, IImmutableSet`1 projects, Func`3 typeMatches, Func`2 shouldContinueSearching, Boolean transitive, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.FindTypesInCurrentProcessAsync(INamedTypeSymbol type, Solution solution, IImmutableSet`1 projects, Boolean transitive, DependentTypesKind kind, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.FindTypesAsync(INamedTypeSymbol type, Solution solution, IImmutableSet`1 projects, Boolean transitive, DependentTypesKind kind, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.FindDerivedClassesArrayAsync(INamedTypeSymbol type, Solution solution, Boolean transitive, IImmutableSet`1 projects, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.InheritanceMargin.AbstractInheritanceMarginService.GetDerivedTypesAndImplementationsAsync(Solution solution, INamedTypeSymbol typeSymbol, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.InheritanceMargin.AbstractInheritanceMarginService.AddInheritanceMemberItemsForNamedTypeAsync(Solution solution, INamedTypeSymbol memberSymbol, Int32 lineNumber, ArrayBuilder`1 builder, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.InheritanceMargin.AbstractInheritanceMarginService.GetSymbolInheritanceChainItemsAsync(Project project, Document document, ImmutableArray`1 symbolAndLineNumbers, Boolean frozenPartialSemantics, 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__DisplayClass7_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, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, 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)
  • Sometimes "CodeLens references" feature fails with the following code stack:
StreamJsonRpc.RemoteInvocationException: The solution does not contain the specified document.
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__156`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__18`1.MoveNext()
RPC server exception:
System.InvalidOperationException: The solution does not contain the specified document.
      at Microsoft.CodeAnalysis.Shared.Extensions.ISolutionExtensions.GetRequiredDocumentAsync(Solution solution, DocumentId documentId, Boolean includeSourceGenerated, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.<>c__DisplayClass6_1.<<DescendInheritanceTreeAsync>g__GetRequiredSemanticModelAsync|4>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.<>c__DisplayClass6_1.<<DescendInheritanceTreeAsync>g__AddSourceTypesThatDeriveFromNameAsync|6>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.<>c__DisplayClass6_0.<<DescendInheritanceTreeAsync>g__AddDescendantSourceTypesInProjectAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.<>c__DisplayClass6_0.<<DescendInheritanceTreeAsync>g__DescendInheritanceTreeInProjectAsync|0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.DescendInheritanceTreeAsync(INamedTypeSymbol type, Solution solution, IImmutableSet`1 projects, Func`3 typeMatches, Func`2 shouldContinueSearching, Boolean transitive, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.FindTypesInCurrentProcessAsync(INamedTypeSymbol type, Solution solution, IImmutableSet`1 projects, Boolean transitive, DependentTypesKind kind, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.DependentTypeFinder.FindTypesAsync(INamedTypeSymbol type, Solution solution, IImmutableSet`1 projects, Boolean transitive, DependentTypesKind kind, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.FindDerivedClassesArrayAsync(INamedTypeSymbol type, Solution solution, Boolean transitive, IImmutableSet`1 projects, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.FindDerivedClassesAsync(INamedTypeSymbol type, Solution solution, Boolean transitive, IImmutableSet`1 projects, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.FindImplementedInterfaceMembersArrayAsync(ISymbol symbol, Solution solution, IImmutableSet`1 projects, Boolean includeImplementationsThroughDerivedTypes, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.SymbolSet.AddUpSymbolsAsync(FindReferencesSearchEngine engine, ISymbol symbol, MetadataUnifyingSymbolHashSet seenSymbols, ArrayBuilder`1 workQueue, ImmutableHashSet`1 projects, Boolean includeImplementationsThroughDerivedTypes, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.SymbolSet.DetermineInitialUpSymbolsAsync(FindReferencesSearchEngine engine, MetadataUnifyingSymbolHashSet initialSymbols, Boolean includeImplementationsThroughDerivedTypes, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.SymbolSet.CreateAsync(FindReferencesSearchEngine engine, MetadataUnifyingSymbolHashSet symbols, Boolean includeImplementationsThroughDerivedTypes, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.PerformSearchAsync(ImmutableArray`1 symbols, Action`1 onReferenceFound, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.PerformSearchAsync(ImmutableArray`1 symbols, Action`1 onReferenceFound, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Shared.Utilities.ProducerConsumer`1.<>c__DisplayClass12_0`2.<<RunChannelAsync>g__ProduceItemsAndWriteToChannelAsync|2>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Shared.Utilities.ProducerConsumer`1.RunChannelAsync[TArgs,TResult](ProducerConsumerOptions options, Func`4 produceItems, Func`4 consumeItems, TArgs args, 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.Remote.RemoteCodeLensReferencesService.<>c__DisplayClass5_0.<<FindReferenceMethodsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass7_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, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, 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.FindReferenceMethodsAsync(Checksum solutionChecksum, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions