-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Description
When compiling a large C# project containing approximately 23,000 types with the runtime-async feature enabled (<Features>$(Features);runtime-async=on</Features>), the Roslyn compiler crashes with a NullReferenceException inside RuntimeAsyncRewriter.VisitAwaitExpression.
The compiler does not emit the source file path or the specific instruction that triggered the failure — neither in the error output nor in the binary log (msbuild.binlog), making it impossible to isolate the exact code that causes the crash.
Stack trace:
Process terminated.
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.VisitAwaitExpression(BoundAwaitExpression node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionOrPatternWithStackGuard(Int32& recursionDepth, BoundNode node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.VisitAssignmentOperator(BoundAssignmentOperator node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionOrPatternWithStackGuard(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionOrPatternWithStackGuard(Int32& recursionDepth, BoundNode node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.VisitExpressionStatement(BoundExpressionStatement node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.DoVisitList[T](ImmutableArray`1 list)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitBlock(BoundBlock node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitSequencePoint(BoundSequencePoint node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.DoVisitList[T](ImmutableArray`1 list)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitBlock(BoundBlock node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Rewrite(BoundStatement node, MethodSymbol method, TypeCompilationState compilationState, BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(TypeCompilationState compilationState)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
at System.Environment.FailFast(System.Runtime.CompilerServices.StackCrawlMarkHandle, System.String, System.Runtime.CompilerServices.ObjectHandleOnStack, System.String)
at System.Environment.FailFast(System.Threading.StackCrawlMark ByRef, System.String, System.Exception, System.String)
at System.Environment.FailFast(System.String, System.Exception)
at Microsoft.CodeAnalysis.ErrorReporting.FailFast.OnFatalException(System.Exception)
at Microsoft.CodeAnalysis.ErrorReporting.FatalError.Report(System.Exception, Microsoft.CodeAnalysis.ErrorReporting.ErrorSeverity, Boolean)
at Microsoft.CodeAnalysis.ErrorReporting.FatalError.ReportAndPropagateUnlessCanceled(System.Exception, Microsoft.CodeAnalysis.ErrorReporting.ErrorSeverity)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
at System.Runtime.EH.FindFirstPassHandler(System.Object, UInt32, System.Runtime.StackFrameIterator ByRef, UInt32 ByRef, Byte* ByRef)
at System.Runtime.EH.DispatchEx(System.Runtime.StackFrameIterator ByRef, ExInfo ByRef)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.VisitAwaitExpression(Microsoft.CodeAnalysis.CSharp.BoundAwaitExpression)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionOrPatternWithStackGuard(Int32 ByRef, Microsoft.CodeAnalysis.CSharp.BoundNode)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(Microsoft.CodeAnalysis.CSharp.BoundNode)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.VisitAssignmentOperator(Microsoft.CodeAnalysis.CSharp.BoundAssignmentOperator)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionOrPatternWithStackGuard(Microsoft.CodeAnalysis.CSharp.BoundNode)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionOrPatternWithStackGuard(Int32 ByRef, Microsoft.CodeAnalysis.CSharp.BoundNode)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(Microsoft.CodeAnalysis.CSharp.BoundNode)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.VisitExpressionStatement(Microsoft.CodeAnalysis.CSharp.BoundExpressionStatement)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(Microsoft.CodeAnalysis.CSharp.BoundNode)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.DoVisitList[[System.__Canon, System.Private.CoreLib, Version=11.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Immutable.ImmutableArray`1<System.__Canon>)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitBlock(Microsoft.CodeAnalysis.CSharp.BoundBlock)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(Microsoft.CodeAnalysis.CSharp.BoundNode)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitSequencePoint(Microsoft.CodeAnalysis.CSharp.BoundSequencePoint)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(Microsoft.CodeAnalysis.CSharp.BoundNode)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.DoVisitList[[System.__Canon, System.Private.CoreLib, Version=11.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Immutable.ImmutableArray`1<System.__Canon>)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitBlock(Microsoft.CodeAnalysis.CSharp.BoundBlock)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(Microsoft.CodeAnalysis.CSharp.BoundNode)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Rewrite(Microsoft.CodeAnalysis.CSharp.BoundStatement, Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol, Microsoft.CodeAnalysis.CSharp.TypeCompilationState, Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(Microsoft.CodeAnalysis.CSharp.TypeCompilationState)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool+WorkerThread.WorkerDoWork(System.Threading.PortableThreadPool)
at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
at System.Threading.Thread.StartCallback()
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.VisitAwaitExpression(BoundAwaitExpression node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionOrPatternWithStackGuard(Int32& recursionDepth, BoundNode node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.VisitAssignmentOperator(BoundAssignmentOperator node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionOrPatternWithStackGuard(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionOrPatternWithStackGuard(Int32& recursionDepth, BoundNode node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.VisitExpressionStatement(BoundExpressionStatement node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.DoVisitList[T](ImmutableArray`1 list)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitBlock(BoundBlock node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitSequencePoint(BoundSequencePoint node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.DoVisitList[T](ImmutableArray`1 list)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitBlock(BoundBlock node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.RuntimeAsyncRewriter.Rewrite(BoundStatement node, MethodSymbol method, TypeCompilationState compilationState, BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileSynthesizedMethods(TypeCompilationState compilationState)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
Reproduction Steps
- Create or use a large C# solution with ~23,000 types, many of which use
async/await. - Target
net11.0and enable the runtime-async preview feature inDirectory.Build.props:
<PropertyGroup>
<TargetFramework>net11.0</TargetFramework>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<Features>$(Features);runtime-async=on</Features>
</PropertyGroup>- Build the solution using .NET SDK
11.0.100-preview.1.26104.118
Unfortunately, I cannot provide a minimal repro because the compiler error does not identify which source file or await expression triggers the crash. The binary log also does not contain this information. If you can point me towards a way to get more diagnostic output from the RuntimeAsyncRewriter, I'm happy to collect additional data.
Expected behavior
The project compiles successfully with the runtime-async feature enabled, or the compiler emits a meaningful error message pointing to the problematic source location.
Actual behavior
The compiler process terminates with a NullReferenceException in RuntimeAsyncRewriter.VisitAwaitExpression. The error is fatal.
Regression?
Unknown. This is our first attempt at enabling runtime-async on this codebase.
Known Workarounds
No response
Configuration
- .NET SDK:
11.0.100-preview.1.26104.118 - Target Framework:
net11.0 - OS: Windows 11 (Build 22631)
- Architecture: x64
- Compiler feature flag:
<Features>$(Features);runtime-async=on</Features> - C# Language Version: mixed (7.2 for legacy projects, 13.0 for newer projects)
- Project scale: ~23,000 types in library that could not be compiled
I have not tested whether this is specific to Windows or to x64. The issue is in the Roslyn compiler itself, so it likely reproduces on any platform with the same SDK version.
Other information
No response