Skip to content

feat!: move reflection and AOT-unsafe APIs into opt-in .Unsafe packages - #4565

Merged
glennawatson merged 10 commits into
mainfrom
feat/split-unsafe-packages
Nov 22, 2026
Merged

glennawatson merged 10 commits into
mainfrom
feat/split-unsafe-packages

Conversation

@glennawatson

@glennawatson glennawatson commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Moves reflection-based and AOT-unsafe APIs out of the core ReactiveUI and platform packages into dedicated opt-in .Unsafe and .Unsafe.Reactive packages, adds reflection-free alternatives and runnable source-generator examples, deduplicates shared internal helpers across the safe and unsafe packages, and updates non-pinned NuGet dependencies.

  • Add 12 opt-in packages (ReactiveUI.Unsafe, ReactiveUI.AndroidX.Unsafe, ReactiveUI.Wpf.Unsafe, ReactiveUI.Maui.Unsafe, ReactiveUI.WinUI.Unsafe, ReactiveUI.Winforms.Unsafe, and their .Reactive counterparts) and add them to src/reactiveui.slnx.
  • Move *Unsafe view hosts and data-template hooks, DependencyResolverMixins.RegisterViewsForViewModels, WithViewsFromAssembly (UnsafeReactiveUIBuilderExtensions), reflection-based AutoPersist/AutoPersistCollection (UnsafeAutoPersistHelperMixins), expression-based ReactivePropertyMixins.AddValidation (UnsafeReactivePropertyMixins), reflection suspension drivers (IUnsafeSuspensionDriver, UnsafeSuspensionHostExtensions, DummySuspensionDriverUnsafe, AppSupportJsonSuspensionDriverUnsafe, BundleSuspensionDriverUnsafe), and Android ControlFetcherMixins + ResolveStrategy into the .Unsafe packages.
  • Add AOT-safe ReactivePropertyMixins.AddValidation(params ValidationAttribute[]) and AddValidation(string? displayName, params ValidationAttribute[]) overloads, and keep ReactiveTableViewSourceExtensions / ReactiveCollectionViewSourceExtensions in the safe Apple packages without stale trim/AOT attributes.
  • Add compiled documentation examples for the new ReactiveUI.SourceGenerators 7.1.0 attributes ([RegisterView], [AutoPersist], [ReactiveValidation], and Android [WireUpControls]/[WireUpResource]/[IgnoreResource]).
  • Extract shared compile-included internal static helpers (SuspensionHostHelpers, AppleAppDirectoryHelper, ItemsControlTemplateBinding, ViewResolutionMessages, AutoPersistMetadataInspector, ReactiveComponentHelpers, ItemViewLayoutHelper, and CombinedReactiveCommand sink helpers) to eliminate duplication without changing public APIs or adding InternalsVisibleTo between production assemblies.
  • Add unit tests covering DummySuspensionDriverUnsafe typed overloads, ReactivePropertyMixins.AddValidation overloads, SuspensionHostHelpers error/completion/synchronous-throw/double-complete paths, and NonNullCastObservable error/completion forwarding.
  • Update non-pinned packages in src/Directory.Packages.props (ReactiveUI.Primitives 10.2.3, ReactiveUI.Binding 12.1.0, ReactiveUI.SourceGenerators 7.1.0, TUnit 1.87.12, SonarAnalyzer.CSharp 10.37.0.15768, Microsoft.Bcl.TimeProvider 11.0.0) and add static to delegate lambdas for ReactiveUI.Binding 12.1.0.
  • Regenerate all affected PublicAPI.txt baselines.

Why

Keeping [RequiresUnreferencedCode] and [RequiresDynamicCode] reflection APIs in the main packages forces trim/AOT warnings onto consumers who never use reflection and bloats the core surface. Separating them into opt-in .Unsafe packages keeps the main packages trim- and Native AOT-clean while giving existing consumers a direct migration path and compile-time alternatives in ReactiveUI.SourceGenerators 7.1.0.

Closes #4561

Breaking changes

  • Reflection-based view hosts (ViewModelViewHostUnsafe, RoutedViewHostUnsafe, AutoDataTemplateBindingHookUnsafe), RegisterViewsForViewModels, WithViewsFromAssembly, reflection AutoPersist/AutoPersistCollection, expression-based ReactivePropertyMixins.AddValidation, reflection suspension drivers, and Android ControlFetcherMixins moved from the core/platform packages to the corresponding *.Unsafe / *.Unsafe.Reactive packages.
  • Consumers using these APIs can either add a reference to the matching .Unsafe package or switch to the compile-time alternatives in ReactiveUI.SourceGenerators ([RegisterView], [AutoPersist], [ReactiveValidation], [WireUpControls]) and the explicit AddValidation(displayName, params ValidationAttribute[]) overload.
  • ReactiveUI.Binding updated to 12.1.0 (delegate-based binding lambdas).

How this was verified

  • Built all affected core, reactive, unsafe, Blazor, MAUI, and documentation example projects in Release with TrackPublicApi=true (0 warnings, 0 errors).
  • Ran ReactiveUI.Tests, ReactiveUI.Tests.Reactive, ReactiveUI.Blazor.Tests, ReactiveUI.Blazor.Tests.Reactive, and ReactiveUI.Maui.Tests on both net10.0 and net11.0 on Linux.
  • Verified the new source-generator documentation examples build and execute cleanly in Release.
  • Verified non-public duplication with a Roslyn structural clone detector.
  • Windows-only and Apple-only runtime UI test suites were not executed locally and rely on CI.

Notes for the reviewer

  • The 12 new .Unsafe / .Unsafe.Reactive projects and src/ReactiveUI.Unsafe.Shared/ mirror the existing project layout and packaging conventions.
  • Shared internal helpers across production assemblies use <Compile Include> rather than InternalsVisibleTo; InternalsVisibleTo is used only for test assemblies.
  • The lambda edits adding static across tests, benchmarks, and docs are mechanical updates for ReactiveUI.Binding 12.1.0's delegate-based APIs under PSH1000.
  • Xamarin.AndroidX.Collection.Jvm stays at 1.6.0.1 because 1.7.0 causes a Cecil XARRA7028 failure on net10.0-android in ReactiveUI.Samples.Maui.

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

- Add 12 opt-in .Unsafe and .Unsafe.Reactive projects for ReactiveUI, AndroidX, WPF, MAUI, WinUI, and WinForms.
- Move *Unsafe view hosts/hooks, RegisterViewsForViewModels, WithViewsFromAssembly, reflection AutoPersist, expression AddValidation, reflection suspension drivers, and Android ControlFetcherMixins into the .Unsafe packages.
- Add reflection-free ReactivePropertyMixins.AddValidation overloads taking explicit ValidationAttribute arrays.
- Update non-pinned NuGet dependencies (ReactiveUI.Primitives 10.2.3, ReactiveUI.Binding 12.1.0, ReactiveUI.SourceGenerators 7.1.0, TUnit 1.87.12, SonarAnalyzer.CSharp 10.37.0.15768, Microsoft.Bcl.TimeProvider 11.0.0) and mark delegate lambdas static.
- Regenerate PublicAPI.txt baselines for all affected assemblies.

BREAKING CHANGE: Reflection-based APIs moved to opt-in *.Unsafe / *.Unsafe.Reactive packages. Use the matching .Unsafe package or the compile-time generators in ReactiveUI.SourceGenerators 7.1.0.
…x Windows/Apple CI

- Add compile-time [RegisterView], [AutoPersist], [ReactiveValidation], and Android [WireUpControls] examples to Documentation pages.
- Mark remaining UIKit, WinForms, and WPF test binding lambdas static for ReactiveUI.Binding 12.1.0 (PSH1000).
- Document InvalidOperationException on AppSupportJsonSuspensionDriverUnsafe.CreateAppDirectory (SST1662).
- Update WPF tests to call DummySuspensionDriverUnsafe and UnsafeReactivePropertyMixins explicitly.
…n across .Unsafe projects

- Extract SuspensionHostHelpers (SubscribeLifecycle, WaitForResult, DriverOperationObserver, PendingLoad) shared between SuspensionHostExtensions and UnsafeSuspensionHostExtensions.
- Extract AppleAppDirectoryHelper.CreateAppDirectory shared between AppSupportJsonSuspensionDriver and AppSupportJsonSuspensionDriverUnsafe.
- Extract ItemsControlTemplateBinding.CreateWpfItemTemplate shared between AutoDataTemplateBindingHook and AutoDataTemplateBindingHookUnsafe.
- Consolidate five duplicate ViewResolutionMessages files into one shared ReactiveUI.Unsafe.Shared/ViewResolutionMessages.cs.
…ability

- Call ItemsControlTemplateBinding.CreateWpfItemTemplate in UnsafeViewResolutionTests.
- Match nullable Expression<Func<ReactiveProperty<string>?>> in ReactivePropertyMixinsTests (CS8620).
… mixins

- Replace repeated multi-line RequiresUnreferencedCode/RequiresDynamicCode string literals with private const string fields in UnsafeAutoPersistHelperMixins and UnsafeSuspensionHostExtensions.
…rMixins and UnsafeAutoPersistHelperMixins

- Extract AutoPersistMetadataInspector.Inspect into src/Shared/Mixins/AutoPersistMetadataInspector.cs and compile-include it into ReactiveUI, ReactiveUI.Reactive, ReactiveUI.Unsafe, and ReactiveUI.Unsafe.Reactive.
@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.93%. Comparing base (c5fc8e4) to head (bc5b6fc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4565      +/-   ##
==========================================
+ Coverage   93.88%   94.93%   +1.05%     
==========================================
  Files         175      184       +9     
  Lines        6112     6086      -26     
  Branches      737      728       -9     
==========================================
+ Hits         5738     5778      +40     
+ Misses        374      308      -66     

☔ 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.

…mmand helpers

- Add HandleFirstRender and SetViewModel helpers in ReactiveComponentHelpers and call them from all four Blazor component bases.

- Extract ItemViewLayoutHelper for MAUI text and image item views and inline BindableProperty change lambdas.

- Share DisposeAll, TryRecordValue, TryFail, and TryComplete helpers across CombinedReactiveCommand sinks.
- Cover DummySuspensionDriverUnsafe typed LoadState and SaveState overloads.

- Cover ReactivePropertyMixins.AddValidation without displayName and with empty attributes.

- Cover SuspensionHostHelpers error, completion, synchronous throw, and double-complete paths.

- Cover NonNullCastObservable error and completion forwarding.
- Wrap a locator driver that only implements ISuspensionDriver so the reflection-based SetupDefaultSuspendResume finds the platform default driver.
- Add a hidden EnsureAppStateLoaded hook so the untyped GetAppState runs the load a typed setup registered.
- Cover the remaining suspension and CombinedReactiveCommand sink lines and branches.
- ReactiveUI.WinUI and ReactiveUI.WinUI.Reactive compile ReactiveUI.Maui/Internal, so the MAUI-only helper broke their builds.
- Keep the helper next to the item views that use it.
@sonarqubecloud

Copy link
Copy Markdown

@glennawatson
glennawatson merged commit 77a7449 into main Nov 22, 2026
19 of 20 checks passed
@glennawatson
glennawatson deleted the feat/split-unsafe-packages branch November 22, 2026 08:15
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.

Apple: RoutedViewHostUnsafe and ViewModelViewHostUnsafe raise IL3050 in every native AOT app, even when unused

1 participant