NullReferenceException when querying diagnostics from unrestored project (Workspace api))
Version Used: 4.14
Steps to Reproduce:
- clone https://github.com/SleepWellPupper/RhoMicro.BindSight/
- checkout
roslyn-nre-repro - do not restore
- run
tests/RoslynNreRepro/RoslynNreRepro.csproj - observe the NRE deep in the
GetDiagnostics()callstack - run restore on the solution
- repeat step 3
- NRE disappears
The repro project loads another project in the solution via the workspace api and gets the compilation. I reproduced this on mac, ubuntu 22.0.4 and windows 11
The loaded project tfm is net8. After changing it to net9, the NRE did not reappear on win11 or ubuntu, it did still occur on mac however.
Another developer (@tebeco) could not repro on his mac. We tried some constellations and had the following results:
| who | installed dotnet version | os | target project tfm | repro? |
|---|---|---|---|---|
| me | 10.0.100-preview.5.25277.114 | Sequoia 15.5 | net8 | yes |
| me | 10.0.100-preview.5.25277.114 | Sequoia 15.5 | net9 | yes |
| me | 9.0.107 | ubuntu 22.0.4 | net8 | yes |
| me | 9.0.107 | ubuntu 22.0.4 | net9 | no |
| tebeco | 10.0.100-preview.4.25258.110 | win11 | net8 | yes |
| tebeco | 10.0.100-preview.4.25258.110 | win11 | net9 | no |
| tebeco | 9.0.300 | win11 | net8 | no |
| tebeco | 9.0.300 | win11 | net9 | no |
| tebeco | 9.0.300 | Sequoia 15.5 | net8 | no |
Expected Behavior: Diagnostics about the unrestored project are returned.
Actual Behavior: An NRE is thrown.
Stacktrace:
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.CodeAnalysis.CSharp.Binder.GetUniqueSignatureFromMethodGroup(BoundMethodGroup node, Boolean& useParams)
at Microsoft.CodeAnalysis.CSharp.Binder.GetMethodGroupDelegateType(BoundMethodGroup node)
at Microsoft.CodeAnalysis.CSharp.BoundMethodGroup.<>c.<GetFunctionType>b__1_0(Binder binder, BoundExpression expr)
at Microsoft.CodeAnalysis.CSharp.Symbols.FunctionTypeSymbol.GetInternalDelegateType()
at Microsoft.CodeAnalysis.CSharp.Symbols.FunctionTypeSymbol.GetHashCode()
at Microsoft.CodeAnalysis.CSharp.NullableWalker.ExpressionAndSymbolEqualityComparer.GetHashCode(ValueTuple`2 obj)
at System.Collections.Immutable.ImmutableDictionary`2.TryGetValue(TKey key, MutationInput origin, TValue& value)
at System.Collections.Immutable.ImmutableDictionary`2.TryGetValue(TKey key, TValue& value)
at Microsoft.CodeAnalysis.CSharp.NullableWalker.SnapshotManager.TryGetUpdatedSymbol(BoundNode node, Symbol symbol, Symbol& updatedSymbol)
at Microsoft.CodeAnalysis.CSharp.NullabilityRewriter.GetUpdatedSymbol[T](BoundNode expr, T sym)
at Microsoft.CodeAnalysis.CSharp.NullabilityRewriter.VisitMethodGroup(BoundMethodGroup node)
at Microsoft.CodeAnalysis.CSharp.BoundMethodGroup.Accept(BoundTreeVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.NullabilityRewriter.VisitCall(BoundCall node)
at Microsoft.CodeAnalysis.CSharp.BoundCall.Accept(BoundTreeVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.NullabilityRewriter.VisitUnaryOperator(BoundUnaryOperator node)
at Microsoft.CodeAnalysis.CSharp.BoundUnaryOperator.Accept(BoundTreeVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.NullabilityRewriter.VisitConversion(BoundConversion node)
at Microsoft.CodeAnalysis.CSharp.BoundConversion.Accept(BoundTreeVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.NullabilityRewriter.VisitIfStatement(BoundIfStatement node)
at Microsoft.CodeAnalysis.CSharp.BoundIfStatement.Accept(BoundTreeVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.DoVisitList[T](ImmutableArray`1 list)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitList[T](ImmutableArray`1 list)
at Microsoft.CodeAnalysis.CSharp.NullabilityRewriter.VisitBlock(BoundBlock node)
at Microsoft.CodeAnalysis.CSharp.BoundBlock.Accept(BoundTreeVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitNonConstructorMethodBody(BoundNonConstructorMethodBody node)
at Microsoft.CodeAnalysis.CSharp.BoundNonConstructorMethodBody.Accept(BoundTreeVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.NullableWalker.Rewrite(ImmutableDictionary`2 updatedNullabilities, SnapshotManager snapshotManager, BoundNode node, ImmutableDictionary`2& remappedSymbols)
at Microsoft.CodeAnalysis.CSharp.NullableWalker.AnalyzeAndRewrite(CSharpCompilation compilation, Symbol symbol, BoundNode node, Binder binder, VariableState initialState, DiagnosticBag diagnostics, Boolean createSnapshots, SnapshotManager& snapshotManager, ImmutableDictionary`2& remappedSymbols)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.BindMethodBody(MethodSymbol method, TypeCompilationState compilationState, BindingDiagnosticBag diagnostics, Boolean includeInitializersInBody, BoundNode initializersBody, Boolean reportNullableDiagnostics, ImportChain& importChain, Boolean& originalBodyNested, Boolean& prependedDefaultValueTypeConstructorInitializer, InitialState& forSemanticModel)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
at Roslyn.Utilities.UICultureUtilities.<>c__DisplayClass5_0.<WithCurrentUICulture>b__0()
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.WaitForWorkers()
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethodBodies(CSharpCompilation compilation, PEModuleBuilder moduleBeingBuiltOpt, Boolean emittingPdb, Boolean hasDeclarationErrors, Boolean emitMethodBodies, BindingDiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnosticsForAllMethodBodies(BindingDiagnosticBag diagnostics, Boolean doLowering, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnosticsWithoutSeverityFiltering(CompilationStage stage, Boolean includeEarlierStages, BindingDiagnosticBag builder, Predicate`1 symbolFilter, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnostics(CompilationStage stage, Boolean includeEarlierStages, DiagnosticBag diagnostics, Predicate`1 symbolFilter, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnostics(CompilationStage stage, Boolean includeEarlierStages, Predicate`1 symbolFilter, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnostics(CancellationToken cancellationToken)
at Program.<Main>$(String[] args) in /home/ubuntu/rhomicro.bindsight/tests/RoslynNreRepro/Program.cs:line 6
at Program.<Main>(String[] args)
Unable to reproduce your issue - how do you execute "run tests/RoslynNreRepro/RoslynNreRepro.csproj".
Unable to reproduce your issue - how do you execute "run tests/RoslynNreRepro/RoslynNreRepro.csproj".
⚠️ Never open the IDE (it could trigger an unwanted restore in the background)
git clone https://github.com/SleepWellPupper/RhoMicro.BindSight/
git checkout -b roslyn-nre-repro origin/roslyn-nre-repro
cd tests/RoslynNreRepro
dotnet run
i used git clean -fdx at root repo level between each runs to unsure there's no .vs/.idea/bin/obj
hint:
when i managed to repro the bug, then running a dotnet restore on the full repo, and then the similar dotnet run above would not trigger the bug, so it's important to keep the entire repo "un-restored" except the dotnet run on that tests/RoslynNreRepro folder
still can't reproduce on my machine it works fine
still can't reproduce on my machine it works fine
https://github.com/tebeco/RhoMicro.BindSight/actions/runs/15699305462/job/44230468770 raw log link in case github lock down the job from the other link: https://productionresultssa5.blob.core.windows.net/actions-results/8491b6b4-e8ff-4688-bdd4-72b8bdfc6d22/workflow-job-run-95f1203d-7a43-5229-aa2f-5a41a7d5a678/logs/job/job-logs.txt?rsct=text%2Fplain&se=2025-06-17T06%3A10%3A12Z&sig=MkrtYbdux%2FshHQtx6Jp9Lgd6mmTJMJ%2Bk8mVwH%2BzRZxI%3D&ske=2025-06-17T16%3A57%3A37Z&skoid=ca7593d4-ee42-46cd-af88-8b886a2f84eb&sks=b&skt=2025-06-17T04%3A57%3A37Z&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skv=2025-05-05&sp=r&spr=https&sr=b&st=2025-06-17T06%3A00%3A07Z&sv=2025-05-05
Per OS:
https://github.com/tebeco/RhoMicro.BindSight/actions/runs/15699387710/job/44230708646
(24.04 don't have preview-5 apparently so discard that run)
seems to repro on 22.x and macos-15 on demand
going further matrix testing with:
- 9.0.300
- 10.0-preview4
- 10.0-preview5
https://github.com/tebeco/RhoMicro.BindSight/actions/runs/15699839760/job/44232030962
We can see that it can impact Windows as well based on the SDK version
still can't reproduce on my machine it works fine
Did you make sure that the dotnet 10 preview5 is installed?
I believe I'm running into this issue as well.
.NET SDK 9.0.301 macOS 15.5
Thanks for reporting this issue. To investigate further we need a complog if this is reliably reproducible, or a heap dump from the crash. You can use the "report feedback" feature in VS to share data privately (just link the created ticket here afterwards).
happened to me too, it seems to me the error is similar:
Feature 'Diagnostic analyzer runner' is currently unavailable due to an internal error.
but it happened when i cut some methods from a class and pasted them in another class
together with another yellow bar crash
Feature 'Missing import discovery' is currently unavailable due to an internal error.
StreamJsonRpc.RemoteInvocationException: Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.CodeAnalysis.CSharp.Binder.GetUniqueSignatureFromMethodGroup(BoundMethodGroup node, Boolean& useParams)
at Microsoft.CodeAnalysis.CSharp.Binder.GetMethodGroupDelegateType(BoundMethodGroup node)
at Microsoft.CodeAnalysis.CSharp.Symbols.FunctionTypeSymbol.GetInternalDelegateType()
at Microsoft.CodeAnalysis.CSharp.Symbols.FunctionTypeSymbol.GetHashCode()
at Microsoft.CodeAnalysis.CSharp.NullableWalker.ExpressionAndSymbolEqualityComparer.GetHashCode(ValueTuple`2 obj)
at Microsoft.CodeAnalysis.CSharp.NullabilityRewriter.GetUpdatedSymbol[T](BoundNode expr, T sym)
at Microsoft.CodeAnalysis.CSharp.NullabilityRewriter.VisitMethodGroup(BoundMethodGroup node)
at Microsoft.CodeAnalysis.CSharp.NullabilityRewriter.VisitCall(BoundCall node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitExpressionStatement(BoundExpressionStatement node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.DoVisitList[T](ImmutableArray`1 list)
at Microsoft.CodeAnalysis.CSharp.NullabilityRewriter.VisitBlock(BoundBlock node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitNonConstructorMethodBody(BoundNonConstructorMethodBody node)
at Microsoft.CodeAnalysis.CSharp.NullableWalker.Rewrite(ImmutableDictionary`2 updatedNullabilities, SnapshotManager snapshotManager, BoundNode node, ImmutableDictionary`2& remappedSymbols)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.BindMethodBody(MethodSymbol method, TypeCompilationState compilationState, BindingDiagnosticBag diagnostics, Boolean includeInitializersInBody, BoundNode initializersBody, Boolean reportNullableDiagnostics, ImportChain& importChain, Boolean& originalBodyNested, Boolean& prependedDefaultValueTypeConstructorInitializer, InitialState& forSemanticModel)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.WaitForWorkers()
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethodBodies(CSharpCompilation compilation, PEModuleBuilder moduleBeingBuiltOpt, Boolean emittingPdb, Boolean hasDeclarationErrors, Boolean emitMethodBodies, BindingDiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.<GetDiagnosticsForMethodBodiesInTree>g__compileMethodBodiesAndDocComments|238_0(SyntaxTree filterTree, Nullable`1 filterSpan, BindingDiagnosticBag bindingDiagnostics, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnosticsForMethodBodiesInTree(SyntaxTree tree, Nullable`1 span, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnosticsForSyntaxTree(CompilationStage stage, SyntaxTree syntaxTree, Nullable`1 filterSpanWithinTree, Boolean includeEarlierStages, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.SyntaxTreeSemanticModel.GetDiagnostics(Nullable`1 span, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.<GetCompilationEventsForSingleFileAnalysis>g__generateCompilationEvents|64_0(Compilation compilation, AnalysisScope analysisScope, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.GetCompilationEventsForSingleFileAnalysis(Compilation compilation, AnalysisScope analysisScope, ImmutableArray`1 additionalFiles, Boolean hasAnyActionsRequiringCompilationEvents, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.ComputeAnalyzerDiagnosticsAsync(AnalysisScope analysisScope, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.GetAnalysisResultCoreAsync(SemanticModel model, Nullable`1 filterSpan, ImmutableArray`1 analyzers, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzersPair.GetAnalysisResultAsync(SemanticModel model, Nullable`1 filterSpan, ImmutableArray`1 projectAnalyzers, ImmutableArray`1 hostAnalyzers, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Diagnostics.Extensions.GetAnalysisResultAsync(CompilationWithAnalyzersPair compilationWithAnalyzers, DocumentAnalysisScope documentAnalysisScope, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Diagnostics.Extensions.GetAnalysisResultAsync(CompilationWithAnalyzersPair compilationWithAnalyzers, DocumentAnalysisScope documentAnalysisScope, Project project, DiagnosticAnalyzerInfoCache analyzerInfoCache, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Remote.Diagnostics.DiagnosticComputer.AnalyzeAsync(CompilationWithAnalyzersPair compilationWithAnalyzers, BidirectionalMap`2 analyzerToIdMap, ImmutableArray`1 projectAnalyzers, ImmutableArray`1 hostAnalyzers, SkippedHostAnalyzersInfo skippedAnalyzersInfo, Boolean logPerformanceInfo, Boolean getTelemetryInfo, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Remote.Diagnostics.DiagnosticComputer.GetDiagnosticsAsync(ImmutableArray`1 projectAnalyzerIds, ImmutableArray`1 hostAnalyzerIds, Boolean logPerformanceInfo, Boolean getTelemetryInfo, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Remote.Diagnostics.DiagnosticComputer.GetNormalPriorityDiagnosticsAsync(ImmutableArray`1 projectAnalyzerIds, ImmutableArray`1 hostAnalyzerIds, Boolean logPerformanceInfo, Boolean getTelemetryInfo, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Remote.RemoteDiagnosticAnalyzerService.<>c__DisplayClass3_0.<<CalculateDiagnosticsAsync>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.RemoteDiagnosticAnalyzerService.CalculateDiagnosticsAsync(Checksum solutionChecksum, DiagnosticArguments arguments, CancellationToken cancellationToken)