Repository navigation
Overview
ReactiveUI 28.0.0 moves every reflection-based and AOT-unsafe API out of the core and platform packages into new opt-in .Unsafe packages. The main packages are now clean for trimming and Native AOT. ReactiveUI.SourceGenerators 7.1.0 adds compile-time replacements for the APIs that moved, so most apps can drop the reflection instead of carrying it.
💥 Why this release is breaking
Before 28.0.0, the core packages shipped APIs marked [RequiresUnreferencedCode] and [RequiresDynamicCode]. On Apple platforms the ...Unsafe view hosts raised IL3050 warnings in every Native AOT app, even apps that never used them, and the app could not suppress those warnings (#4561).
The fix is to keep those APIs out of the assemblies that every app references. If your code calls one of them, it no longer compiles against the core package alone. You have two ways forward:
- Add the matching
.Unsafepackage. The types keep their names and namespaces, so in most cases a package reference and a rebuild is all you need. - Switch to the compile-time alternative in
ReactiveUI.SourceGenerators7.1.0, described below. This is the recommended path for trimmed and Native AOT apps.
New opt-in packages
| Package | .Reactive variant |
|---|---|
ReactiveUI.Unsafe |
ReactiveUI.Unsafe.Reactive |
ReactiveUI.Wpf.Unsafe |
ReactiveUI.Wpf.Unsafe.Reactive |
ReactiveUI.Winforms.Unsafe |
ReactiveUI.Winforms.Unsafe.Reactive |
ReactiveUI.WinUI.Unsafe |
ReactiveUI.WinUI.Unsafe.Reactive |
ReactiveUI.Maui.Unsafe |
ReactiveUI.Maui.Unsafe.Reactive |
ReactiveUI.AndroidX.Unsafe |
ReactiveUI.AndroidX.Unsafe.Reactive |
These packages are not trimmable and not AOT compatible by design. Apps that stay trim and AOT safe do not need them.
What moved, and what to use instead
| API that moved | Now in | Compile-time alternative |
|---|---|---|
ViewModelViewHostUnsafe, RoutedViewHostUnsafe, AutoDataTemplateBindingHookUnsafe, ViewModelControlHostUnsafe, RoutedControlHostUnsafe |
The platform .Unsafe package (ReactiveUI.Unsafe for Apple and Android) |
ViewModelViewHost and RoutedViewHost with [RegisterView] |
RegisterViewsForViewModels(assembly) and WithViewsFromAssembly(assembly) |
ReactiveUI.Unsafe |
[RegisterView] and RegisterGeneratedViews() |
AutoPersist and AutoPersistCollection overloads without metadata |
ReactiveUI.Unsafe |
[AutoPersist] and the overloads that take AutoPersistMetadata |
ReactiveProperty<T>.AddValidation(() => Property) |
ReactiveUI.Unsafe |
[ReactiveValidation], or the new AddValidation(displayName, params ValidationAttribute[]) |
Untyped ISuspensionHost members: GetAppState<T>(), ObserveAppState<T>(), SetupDefaultSuspendResume() |
ReactiveUI.Unsafe |
ISuspensionHost<TAppState> with a source-generated JsonTypeInfo<TAppState> |
Android ControlFetcherMixins (WireUpControls, GetControl), ResolveStrategy, LayoutViewHostUnsafe, ReactiveViewHostUnsafe |
ReactiveUI.Unsafe and ReactiveUI.AndroidX.Unsafe |
[WireUpControls] |
Suspension drivers
ISuspensionDriver now only has the JsonTypeInfo<T> members. The reflection-based LoadState() and SaveState<T>(T) moved to a new interface, IUnsafeSuspensionDriver, in ReactiveUI.Unsafe.
- A custom driver that only needs the typed members needs no change beyond removing the two reflection methods if you no longer want them.
- A custom driver that must keep reflection-based serialization should implement
IUnsafeSuspensionDriver. DummySuspensionDriverUnsafe,BundleSuspensionDriverUnsafe(Android) andAppSupportJsonSuspensionDriverUnsafe(Apple) are the reflection-capable twins of the built-in drivers.- With
ReactiveUI.Unsafereferenced, the untypedSetupDefaultSuspendResume()still finds the driver the platform registered, and the untypedGetAppState<T>()still loads state for a host that was set up through the typed overload.
Other changes in this release
- New reflection-free
ReactivePropertyMixins.AddValidation(params ValidationAttribute[])andAddValidation(string? displayName, params ValidationAttribute[])in the core package. IReactiveUIBuilder.WithViewsFromAssemblyis no longer an interface member. It is an extension method inReactiveUI.Unsafe.ReactiveUI.Bindingis updated to 12.1.0 andReactiveUI.Primitivesto 10.2.3.
✨ Automating the wiring with ReactiveUI.SourceGenerators 7.1.0
ReactiveUI.SourceGenerators 7.1.0 adds four generators. Each one replaces a piece of wiring that used to need reflection at run time, or careful hand-written code, with code generated at build time.
[RegisterView]: view registration without assembly scanning
Mark each view. The generator writes one RegisterGeneratedViews() extension method that registers them all. [RegisterView<TViewModel>] also takes a contract and a singleton flag.
[RegisterView]
public sealed class PlaylistView : IViewFor<PlaylistViewModel> { /* ... */ }
[RegisterView<PlaylistViewModel>(Contract = "compact", IsSingleton = true)]
public sealed class CompactPlaylistView : IViewFor<PlaylistViewModel> { /* ... */ }
// At startup, in place of WithViewsFromAssembly(...):
builder.RegisterGeneratedViews().BuildApp();[AutoPersist]: persistence metadata without reflection
Add [AutoPersist] to a partial [DataContract] class. The generator writes a static AutoPersistMetadata property that lists the [DataMember] properties, so AutoPersist never has to inspect the type at run time.
[DataContract]
[AutoPersist]
public sealed partial class Note : ReactiveObject
{
[DataMember]
public string Title { get; set => this.RaiseAndSetIfChanged(ref field, value); } = string.Empty;
}
note.AutoPersist(SaveAsync, Note.AutoPersistMetadata, TimeSpan.FromSeconds(3));[ReactiveValidation]: DataAnnotations on ReactiveProperty<T> without expressions
Add [ReactiveValidation] to a partial class. The generator writes a ConfigureValidation() method that applies each property's validation attributes and its [Display(Name = ...)] through the new reflection-free AddValidation overload.
[ReactiveValidation]
public sealed partial class SignupModel
{
public SignupModel() => ConfigureValidation();
[Display(Name = "Student Name")]
[Required(ErrorMessage = "Enter the student's name.")]
public ReactiveProperty<string> Name { get; } = new(string.Empty);
[Range(8, 18)]
public ReactiveProperty<int> Age { get; } = new(5);
}[WireUpControls]: Android control wiring without resource reflection
The attributes live in the ReactiveUI.SourceGenerators.Android namespace. The generator writes a WireUpControls() method that calls FindViewById<T>(Resource.Id.*) for each control property. Fragments get WireUpControls(View rootView). Use [WireUpResource("id")] when the resource name differs from the property name, and [IgnoreResource] to skip a property.
[WireUpControls]
public sealed partial class AbsenceActivity : ReactiveAppCompatActivity<AbsenceViewModel>
{
[WireUpResource("statusLabel")]
public TextView? StatusText { get; set; }
[IgnoreResource]
public TextView? ScratchLabel { get; set; }
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_absence);
WireUpControls();
}
}Runnable versions of all four examples are in src/examples/Documentation.
🗞️ What's Changed
💥 Breaking Changes
- 77a7449 feat!: move reflection and AOT-unsafe APIs into opt-in .Unsafe packages (#4565) @glennawatson
🐛 Fixes
- 0fc845f fix: preserve typed notifications after binding setup (#4559) @glennawatson
📦 Dependencies
🔗 Full Changelog: 27.0.1...28.0.0
🙌 Contributions
💖 Thanks to all the contributors: @glennawatson
Automated services that contributed: renovate[bot]