Repository navigation
Description
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:
dynamic model = updatedModel;: ViewModelGenTool_3.cs#L191{GetAwait()}{model}.{Method}(...): CommandFromMethod.CommandConfigGenerator.cs#L81-L108
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);
}- Add
public IState<int> Step => State.Value(this, () => 1);and save: applied. - Change
Increment(CancellationToken ct)toIncrement(int step, CancellationToken ct)and save:InternalError. - Any later edit, even a body-only one:
InternalErroragain.
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
- EnC: adding an async lambda that awaits a
dynamiccall throws InvalidOperationException in DeltaMetadataWriter.GetFieldDefinitionHandle dotnet/roslyn#86045: the underlying compiler bug. This workaround can be reverted once it's fixed. - Separately, the DevServer could treat this exception as a rude edit and not leave the session wedged; that part belongs in unoplatform/uno.
Activity
dr1rrb commentedon Oct 14, 2026
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:
IsAwaitabledoesn't only acceptTask/ValueTask, it also accepts any type with an instance or extensionGetAwaiter. So the cast should use the method's actual return type (fully qualified), not a hard-codedTask/ValueTask. For the extensionGetAwaitercase, the generated file also needs that extension's namespace in scope once the await is static (today it can't bind throughdynamicanyway, so that's a fix rather than a regression).fix(reactive): Import extension GetAwaiter when awaiting a command call
fix(reactive): Cast awaited command calls to their return type before…