Skip to content

Opt-in into runtime async for all .NET 12+ projects - #138389

Open
jkotas wants to merge 1 commit into
dotnet:mainfrom
jkotas:runtime-async
Open

jkotas wants to merge 1 commit into
dotnet:mainfrom
jkotas:runtime-async

Conversation

@jkotas

@jkotas jkotas commented Nov 26, 2026

Copy link
Copy Markdown
Member

No description provided.

@azure-pipelines

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

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

and '$(IsPackable)' != 'true'
and $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net11.0'))
and '$(UseRuntimeAsync)' != 'false'">
<!-- Enable runtime async for .NET 12+ source projects. -->

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the runtime-async is on by default in the .NET SDK, we should be able to delete this

@MichalStrehovsky

Copy link
Copy Markdown
Member

If someone is on .NET 11 on Windows, using System.Text.Json and upgrades to .NET 12 System.Text.Json would they lose runtime async from it?

@MichalStrehovsky MichalStrehovsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, we never enabled runtime async on something that is packable even if it was a e.g. net11.0-windows build.

@MichalStrehovsky

Copy link
Copy Markdown
Member

This will probably not pass the CI due to the crossgen2 crash I saw in #138347, but at least now there is a PR and it won't get lost.

@akoeplinger

Copy link
Copy Markdown
Member

The crossgen2 assert in the browser-wasm build (!signatureMethod.IsCompilerGeneratedILBodyForAsync() in ILBodyFixupSignature) is a crossgen2 bug exposed by this change, not a problem in the libraries. It's fixed in #138405.

Note

This comment was generated with GitHub Copilot.

kubaflo added a commit to dotnet/maui that referenced this pull request Nov 29, 2026
<!-- copilot-assessment:v1 -->
### Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: `8dc4c8067df4d45478b93d52eab85aab0febce56`

| Dimension | Assessment | Rationale |
|---|---|---|
| Change confidence | 8/10 | ↑ The full MAUI package solution rebuilt
and packed at the assessed revision.<br>↑ MSBuild evaluation confirmed
net12 enables `runtime-async=on`, net11/netstandard remain unchanged,
and an explicit `runtime-async=off` is preserved.<br>↑ The Android
sample-content benchmark installed and launched with the feature; APK
size fell 0.48%.<br>↓ The .NET 12 upstream default-on rollout is still
open, and broad physical-device/CI runtime validation remains pending. |
<!-- /copilot-assessment -->

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

Enables [Runtime Async
V2](https://learn.microsoft.com/dotnet/core/whats-new/dotnet-11/runtime#runtime-async)
for the current .NET 12 target in both places MAUI compilation is
configured:

- In-tree MAUI projects receive the compiler feature in
`Directory.Build.targets`.
- The packaged MAUI SDK applies the same default to net12 consumer
projects through `BundledVersions.targets`.

The setting is idempotent and scoped to net12. It leaves net11 and .NET
Standard assets unchanged and does not replace an explicit
`runtime-async` selection, so a project can opt out with
`Features=runtime-async=off`.

#### What Runtime Async changes

Today, C# normally implements an `async` method by generating a
state-machine type and `MoveNext` method. Runtime Async instead marks
eligible methods with the runtime async metadata contract and lets the
runtime/JIT track suspension and resumption. The [draft ECMA-335
specification](https://github.com/dotnet/runtime/blob/main/docs/design/specs/runtime-async.md),
originally introduced by
[dotnet/runtime#104063](dotnet/runtime#104063),
documents the `MethodImplOptions.Async` method contract and
`AsyncHelpers` await operations.

The practical benefits are narrower, cleaner live stack traces/debugger
views, fewer compiler-generated async state-machine types, and
additional JIT opportunities such as directly calling runtime-async
variants and avoiding intermediate task/continuation work. The [.NET 11
performance deep
dive](https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-11/#runtime-async)
covers those optimizations and also notes the current boundaries:
Runtime Async supports `Task`, `Task<T>`, `ValueTask`, and
`ValueTask<T>`, while `async void`, async iterators, and arbitrary
custom task-like builders continue to use the traditional
transformation.

Runtime Async supports both ReadyToRun and NativeAOT in .NET 11. The
corresponding upstream R2R and NativeAOT tracking issues are
[dotnet/runtime#115098](dotnet/runtime#115098)
and
[dotnet/runtime#124101](dotnet/runtime#124101);
the latter is complete and the former is closed with its implementation
work substantially complete.

#### .NET rollout and why .NET 12

The [upstream Runtime Async tracking
issue](dotnet/runtime#109632) is now on the
**.NET 12.0 milestone**. Its current status distinguishes the two stages
of rollout:

1. **.NET 11:** Runtime Async is available without preview-only
`EnablePreviewFeatures`; however, application code still opts in with
`runtime-async=on`. The runtime libraries/shared framework are already
compiled with it. See the [Microsoft Learn runtime
guide](https://learn.microsoft.com/dotnet/core/whats-new/dotnet-11/runtime#runtime-async)
and [.NET 11
overview](https://learn.microsoft.com/dotnet/core/whats-new/dotnet-11/overview).
2. **.NET 12:** This is the intended defaulting point. In [the tracking
issue's October 2026
guidance](dotnet/runtime#109632 (comment)),
a runtime maintainer states that Runtime Async is opt-in in .NET 11
because Mono does not support it, but in .NET 12 Mono goes away and
Runtime Async becomes the default.
[dotnet/runtime#134397](dotnet/runtime#134397)
tracks removal of the .NET 12 Mono runtime packs and already links the
related MAUI cleanup work.

There is a concrete upstream rollout PR: [dotnet/runtime#138389, “Opt-in
into runtime async for all .NET 12+
projects”](dotnet/runtime#138389). As of
2026-11-29 it is **open**, with approvals but not yet merged; a reviewer
notes that this repository-level opt-in should be removable once the
.NET SDK defaults it on. The PR also exposed a crossgen2 issue now being
addressed in
[dotnet/runtime#138405](dotnet/runtime#138405).

Earlier rollout work already auto-enabled Runtime Async for supported
shared-framework net11+ sources and removed the runtime configuration
knob in
[dotnet/runtime#125406](dotnet/runtime#125406),
with a corresponding .NET 11 preview backport in
[dotnet/runtime#126343](dotnet/runtime#126343).
This MAUI PR therefore targets the same transition for MAUI's .NET 12
source and packages without changing net11 or netstandard compatibility.

#### Android sample-content benchmark

The generated `maui --sample-content` app was compared in Release for
`android-arm64` with CoreCLR, ReadyToRun, and `TrimMode=partial`:

| Metric | Default | Runtime Async | Delta |
|---|---:|---:|---:|
| Signed APK | 21,319,306 B | 21,216,906 B | **−102,400 B (−0.48%)** |
| Signed AAB | 20,619,137 B | 20,517,222 B | **−101,915 B (−0.49%)** |
| Cold-process startup median | 766.0 ms | 780.5 ms | **+14.5 ms
(+1.9%)** |

The package reduction came entirely from `libassembly-store.so`. Startup
used 20 `am start -W -S` launches per variant across two speed-compiled,
warmed blocks on an ARM64 API 35 emulator. IQRs overlapped (710.5–819.25
ms vs. 747.75–825.5 ms) and paired block deltas had opposite signs, so
there was no demonstrated startup improvement or regression.

#### Validation

- `./.dotnet/dotnet msbuild eng/Microsoft.Maui.Packages-mac.slnf
-restore '-t:Rebuild;Pack' -p:Configuration=Release -p:Pack=true -m
-v:minimal` — **passed** at the assessed revision.
- `./.dotnet/dotnet build src/Core/src/Core.csproj -c Release -f
net12.0-android37.0 -t:Rebuild --no-restore -v:minimal` — **passed**.
- MSBuild `Features` evaluation — **net12 defaults to
`runtime-async=on`**, `runtime-async=off` is preserved, and
net11/netstandard remain unchanged.

### Issues Fixed

N/A — no issue was provided.

### Let AI finish this PR

- [ ] **Let the MAUI agent address review feedback and fix remaining
issues on this PR.** Maintainers still decide whether it is merged. For
PRs from forks, the agent opens a follow-up PR that keeps your commits.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.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.

4 participants