Skip to content

[HR][MVUX] Generated command lambdas await a dynamic value, which crashes Roslyn EnC; cast the call before awaiting #3227

Closed

Description

@kazo0

Current behavior

For each command, MVUX generates an async Execute lambda in __Reactive_BindableInitializeForUpdatedModel, the method that re-initializes the view model after a Hot Reload update. There the model is dynamic (dynamic model = updatedModel;), and the lambda awaits the dynamic call directly:

Execute = async (reactive_commandParameter, reactive_ct) =>
{
    await model.Increment(reactive_ct);   // awaits a dynamic value
}

Awaiting a dynamic value inside a lambda, in a method where another lambda already captures the same dynamic local, crashes Roslyn's EnC delta writer when an edit adds or replaces that lambda: dotnet/roslyn#86045. Uno's DevServer then reports InternalError for that edit and for every later edit until the app restarts.

In practice: change a command's parameters while the app runs (for example Increment(CancellationToken ct) → Increment(int step, CancellationToken ct)), and Hot Reload is stuck until a restart.

Generated here:

Proposed workaround

When the method is awaitable, cast the call to the method's declared return type before awaiting it, so the await is on a statically typed Task/ValueTask and not on dynamic:

await ((global::System.Threading.Tasks.ValueTask)model.Increment(reactive_ct));

The call itself stays dynamic, so it still binds to the updated model. The return type is known at generation time, and the generator re-runs on each edit, so the cast always matches the current model. The cast is also harmless where the model is statically typed (the constructor path shares this code).

In the console repro of dotnet/roslyn#86045, which reproduces the same shape, this variant applies cleanly where the uncast await crashes:

Added lambda Result
async ct => await model.Increment(ct) crash
async ct => await (Task)model.Increment(ct) applied

I haven't built a patched generator to confirm it end to end in an Uno app.

Expected behavior

Changing a command's signature through Hot Reload either applies or is reported as a rude edit, without wedging later edits.

How to reproduce

On an app created from the recommended preset (MVUX, Navigation), Skia desktop, fresh DevServer:

public partial record MainModel
{
    public IState<int> Count => State.Value(this, () => 0);
    public async ValueTask Increment(CancellationToken ct) => await Count.UpdateAsync(c => c + 1, ct);
}
  1. Add public IState<int> Step => State.Value(this, () => 1); and save: applied.
  2. Change Increment(CancellationToken ct) to Increment(int step, CancellationToken ct) and save: InternalError.
  3. Any later edit, even a body-only one: InternalError again.

DevServer host log at step 2:

[Warn] Internal error while processing hot-reload (Unexpected value 'Preflight.Presentation.MainViewModel.<>c__DisplayClass10_0.<<__Reactive_BindableInitializeForUpdatedModel>b__4#2>d.<>o.<>p__0' of type 'Microsoft.CodeAnalysis.CSharp.Symbols.SynthesizedFieldSymbol').
Scripted run (driven through the App MCP)
[E1 add Step state] exit=0 | edit to 'Preflight\Presentation\MainModel.cs': applied (server op #1 Success in 2.7s, local op #2 Success in 0.4s, types: MainModel, MainViewModel)
[E2 command signature Increment(int step)] exit=1 | edit to 'Preflight\Presentation\MainModel.cs': NOT applied — server op #2 InternalError in 0.5s.
[E3 command body after E2] exit=1 | edit to 'Preflight\Presentation\MainModel.cs': NOT applied — server op #3 InternalError in 0.4s.

Making the signature change the first edit applies, which matches the Roslyn trigger: the crash needs a capturing lambda already in the previous generation.

Environment

  • Uno.WinUI 7.0.0-dev.2270, Uno.Extensions.Reactive 8.0.0-dev.76, Uno.Sdk 7.0.0-dev.73
  • DevServer host 7.0.0-dev.2270; .NET SDK 10.0.400 (Roslyn 5.9.0-1.26379.115)
  • Skia desktop (Windows 11). Not platform specific: the crash is in the DevServer's compilation.

Related

Activity

  1. added
    kind/bug
    triage/untriaged
    on Oct 14, 2026
  2. dr1rrb commented on Oct 14, 2026

    @dr1rrb
    Member

    Makes sense to me. Casting to the declared return type is the right seam: the call stays dynamic so it still binds to the updated model, only the await becomes static, and it's a no-op on the ctor path.

    Small note for the implementation: IsAwaitable doesn't only accept Task/ValueTask, it also accepts any type with an instance or extension GetAwaiter. So the cast should use the method's actual return type (fully qualified), not a hard-coded Task/ValueTask. For the extension GetAwaiter case, the generated file also needs that extension's namespace in scope once the await is static (today it can't bind through dynamic anyway, so that's a fix rather than a regression).

  3. self-assigned this
    on Oct 14, 2026
  4. added a commit that references this issue on Nov 6, 2026
    8c4ecc7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/mvuxkind/bugtriage/untriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions