Skip to content

fix: make view WhenActivated trim and AOT safe; build without runtime-async - #4532

Merged
glennawatson merged 1 commit into
mainfrom
fix/aot-safe-view-activation
Oct 3, 2026
Merged

glennawatson merged 1 commit into
mainfrom
fix/aot-safe-view-activation

Conversation

@glennawatson

@glennawatson glennawatson commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

View WhenActivated is now trim and AOT safe, and the .NET 11 build no longer uses runtime-async.

  • View activation watches the view's ViewModel through the registered ICreatesObservableForProperty plugin, as the binding source generator does, instead of reflection.
  • When no plugin can watch the property, activation reports the current ViewModel once.
  • [RequiresUnreferencedCode] is removed from every view WhenActivated overload, including the WPF ones.
  • The design-mode branch in view activation is removed, because it could never run.
  • The .NET 11 assemblies are built without runtime-async, which Mono does not support.
  • Updates ReactiveUI.Binding to 9.0.0, TUnit, SonarAnalyzer.CSharp, and the Blazor WASM example's ASP.NET Core components.

Why

Any app that called this.WhenActivated(...) in a view, or derived from a platform base that does, got trim warnings when published with Native AOT. Separately, Blazor WebAssembly, Avalonia's browser apps and other Mono hosts can fail on a runtime-async build.

Breaking changes

The .NET 11 assemblies no longer use runtime-async. The public API does not change apart from dropping [RequiresUnreferencedCode]. This ships as a major release because of the runtime change.

How this was verified

A new test covers activation when no plugin can watch the ViewModel. Existing activation tests cover ViewModel swap and clear while active. The WinForms and WPF suites were run on Windows.

Notes for the reviewer

Start with ObserveViewModel in ViewForMixins.cs, which mirrors the generator's plugin path. The removed design-mode branch called IActivatableView.GetIsDesignMode(), which always returns false in this assembly. WinForms and WPF still check design mode in their own code. The WPF baseline updates are mechanical.

Checklist

  • I have read the Contribute guide
  • The PR title follows Conventional Commits
  • Tests cover this change, or the summary says why they do not
  • New or changed public API has XML documentation

@glennawatson
glennawatson marked this pull request as draft October 3, 2026 04:58
@glennawatson
glennawatson force-pushed the fix/aot-safe-view-activation branch from a391c68 to 08df06b Compare October 3, 2026 06:46
@glennawatson glennawatson changed the title fix: make view WhenActivated trim and AOT safe fix: make view WhenActivated trim and AOT safe; build without runtime-async Oct 3, 2026
@glennawatson
glennawatson marked this pull request as ready for review October 3, 2026 06:46
@codecov

codecov Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.75%. Comparing base (9e5e699) to head (f0bca16).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4532      +/-   ##
==========================================
+ Coverage   93.69%   93.75%   +0.06%     
==========================================
  Files         175      175              
  Lines        6231     6182      -49     
  Branches      743      736       -7     
==========================================
- Hits         5838     5796      -42     
+ Misses        392      386       -6     
+ Partials        1        0       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Watch IViewFor.ViewModel through the registered ICreatesObservableForProperty plugin, as the binding generator does, instead of WhenAnyValueUnsafe.
- Fall back to the current ViewModel once when no plugin can watch the property.
- Remove RequiresUnreferencedCode from the IActivatableView and WPF WhenActivated overloads.
- Remove the design-mode branch in view activation. IActivatableView.GetIsDesignMode always returns false there, so it never ran.
- Update the WPF public API baselines.
- Build the .NET 11 assemblies without runtime-async. Mono does not support it, so it breaks Blazor WebAssembly and other Mono hosts.
- Update ReactiveUI.Binding to 9.0.0, TUnit to 1.72.16, SonarAnalyzer.CSharp to 10.35.0.4138 and the Blazor WASM example's Microsoft.AspNetCore.Components to 10.0.12.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@glennawatson
glennawatson force-pushed the fix/aot-safe-view-activation branch from 08df06b to f0bca16 Compare October 3, 2026 08:10
@sonarqubecloud

sonarqubecloud Bot commented Oct 3, 2026

Copy link
Copy Markdown

@glennawatson
glennawatson merged commit b3af5ad into main Oct 3, 2026
19 checks passed
@glennawatson
glennawatson deleted the fix/aot-safe-view-activation branch October 3, 2026 09:41
glennawatson added a commit that referenced this pull request Oct 3, 2026
…-async (#4532)

- Watch IViewFor.ViewModel through the registered ICreatesObservableForProperty plugin, as the binding generator does, instead of WhenAnyValueUnsafe.
- Fall back to the current ViewModel once when no plugin can watch the property.
- Remove RequiresUnreferencedCode from the IActivatableView and WPF WhenActivated overloads.
- Remove the design-mode branch in view activation. IActivatableView.GetIsDesignMode always returns false there, so it never ran.
- Update the WPF public API baselines.
- Build the .NET 11 assemblies without runtime-async. Mono does not support it, so it breaks Blazor WebAssembly and other Mono hosts.
- Update ReactiveUI.Binding to 9.0.0, TUnit to 1.72.16, SonarAnalyzer.CSharp to 10.35.0.4138 and the Blazor WASM example's Microsoft.AspNetCore.Components to 10.0.12.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants