Skip to content

[release/11.0] Reject runtime-async methods lazily on Mono - #138002

Draft
pavelsavara wants to merge 3 commits into
release/11.0from
pavelsavara/mono-asyncv2-load-rejection
Draft

pavelsavara wants to merge 3 commits into
release/11.0from
pavelsavara/mono-asyncv2-load-rejection

Conversation

@pavelsavara

@pavelsavara pavelsavara commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Fixes Issue #137984

main PR: None; this draft targets release/11.0 directly.

Description

Mono allows assemblies with runtime-async methods to load and lets their ordinary methods run. The interpreter and JIT reject attempts to execute a flagged method, and the AOT compiler emits a body that throws when called. All three paths produce a PlatformNotSupportedException naming the method and assembly before the original body runs. The AOT message adds (compiled with Mono AOT), which lets the regression test distinguish execution of the generated throw body from interpreter fallback. The shared formatter frees the temporary method name after building the diagnostic. There is no assembly-load scan or post-ILLink validation.

Customer Impact

A customer migrating to .NET 11 enabled runtime-async=on in their root Directory.Build.props. Their Mono-based Blazor WebAssembly app failed at startup without a useful explanation. The new exception identifies the unsupported method and its assembly so customers can rebuild it without runtime-async.

Regression

No known regression in previously supported Mono behavior. This addresses the failure mode when adopting runtime-async during a .NET 11 migration.

Testing

The branch is based on release/11.0 at a6104ef89fc2. The focused Browser tests used a workload whose Mono runtime and AOT cross-compiler packages both matched the rebuilt packages by SHA-256.

  • Passed: Mono Browser Debug build.
    .\build.cmd -bl -os browser -subset mono+libs+packs -c Debug /p:RuntimeFlavor=Mono /p:EnableHotReloadInRuntimeConfigDevFile=false
  • Passed (2/2) on 2066f9a8a61f: Browser interpreter and AOT regressions verify that ordinary code runs and the flagged method throws before executing its original body. The AOT test verifies that the original IL was stripped and that the exception contains the AOT-only marker. The interpreter test verifies that the marker is absent.
    $sdk = (Resolve-Path .\artifacts\bin\dotnet-async-review).Path
    .\dotnet.cmd build -bl /p:TargetOS=browser /p:TargetArchitecture=wasm /p:RuntimeFlavor=Mono /p:Configuration=Debug '/t:Build;Test' .\src\mono\wasm\Wasm.Build.Tests\ /p:TestUsingWorkloads=true /p:InstallWorkloadForTesting=false /p:InstallChromeForTests=false "/p:SdkWithWorkloadForTestingPath=$sdk\" '/p:XUnitMethodName=Wasm.Build.Tests.WasmBuildAppTest.RuntimeAsyncMethodIsRejected*'
  • Failed as expected (1/1): The updated AOT test ran against the previous workload and failed specifically on the missing AOT marker.
    $sdk = (Resolve-Path .\artifacts\bin\dotnet-async-lazy-final).Path
    .\dotnet.cmd build -bl /p:TargetOS=browser /p:TargetArchitecture=wasm /p:RuntimeFlavor=Mono /p:Configuration=Debug '/t:Build;Test' .\src\mono\wasm\Wasm.Build.Tests\ /p:TestUsingWorkloads=true /p:InstallWorkloadForTesting=false /p:InstallChromeForTests=false "/p:SdkWithWorkloadForTestingPath=$sdk\" '/p:XUnitMethodName=Wasm.Build.Tests.WasmBuildAppTest.RuntimeAsyncMethodIsRejected_AOT'
  • Passed: Windows x64 Mono native rebuild after the diagnostic fixes. With the x64 Visual Studio build environment initialized, ran:
    cmake --build .\artifacts\obj\mono\windows.x64.Debug --target install --config Debug
  • Passed (4/4) before the diagnostic fixes; not rerun afterward: Existing synchronous and asynchronous Main cases in Debug and Release.
    $sdk = (Resolve-Path .\artifacts\bin\dotnet-async-lazy-final).Path
    .\dotnet.cmd build -bl /p:TargetOS=browser /p:TargetArchitecture=wasm /p:RuntimeFlavor=Mono /p:Configuration=Debug '/t:Build;Test' .\src\mono\wasm\Wasm.Build.Tests\ /p:TestUsingWorkloads=true /p:InstallWorkloadForTesting=false /p:InstallChromeForTests=false "/p:SdkWithWorkloadForTestingPath=$sdk\" '/p:XUnitMethodName=Wasm.Build.Tests.WasmBuildAppTest.*AsyncMain'
  • Passed before the diagnostic fixes; not rerun afterward: Local Windows x64 Mono smoke probe in JIT (mono-sgen.exe --optimize=inline Probe.dll) and interpreter (mono-sgen.exe --interp Probe.dll) modes. Both executed ordinary code and threw the expected exception without executing the flagged method body.

Risk

The change is Mono-only. It checks an existing method flag during code preparation and prevents flagged methods from being inlined. Assembly loading is unchanged. The main risk is in AOT code generation, where flagged methods get a throwing body instead of their original IL; the Browser AOT regression covers that path. Mobile AOT was not tested locally.

Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.

Resolves #137984

Note

This description was prepared with GitHub Copilot.

Reject executable images that contain runtime-async methods, even if those
methods are never called. Log the assembly name and report browser export
binding failures without aborting the runtime.

Cover startup and dependency loading in Wasm.Build.Tests.

Related: #137984

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@jkotas

jkotas commented Nov 20, 2026

Copy link
Copy Markdown
Member

The change is Mono-only, but it adds a linear MethodDef scan to each executable image load.

Is this upfront scan the best way to do this? It looks expensive. I would expect that we will check for the runtime async bit lazily right before the method is executed and produce good error message at that point.

Keep assemblies loadable without scanning their MethodDef tables. Reject unsupported methods in the interpreter and JIT, and emit a throwing body in Mono AOT so the failure occurs only on invocation.

Related: #137984

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pavelsavara pavelsavara changed the title [release/11.0] Reject assemblies with runtime-async methods on Mono [release/11.0] Reject runtime-async methods lazily on Mono Nov 24, 2026
Free the formatted method name after building the exception message. Identify the generated AOT throw body in the diagnostic so the Browser regression can distinguish native execution from interpreter fallback.

Related: #137984

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants