Hot Reload for AvaloniaNews

Hot Reload for Avalonia

Hot Reload has topped our user research for years. The first request landed in 2019, and in our most recent survey, it scored higher than any other feature we asked about: 70% of respondents noted they were ‘extremely interested’, and only 4% had ‘no interest’ at all. Today we’re pleased to share that we’re shipping it.

AvaloniaUI.DiagnosticsSupport.HotReload applies your .axaml and .cs edits to a running application without restarting it. Save a file, and the matching controls, styles, resources and data templates rebuild in place. It’s generally available now on Windows, macOS, Linux, iOS and Android.

Getting started requires three steps.

  1. Install the AvaloniaUI.DiagnosticsSupport.HotReload NuGet package
  2. Add your AvaloniaUILicenseKey to the application project,
  3. Run the app with dotnet watch, Visual Studio, or Visual Studio Code with C# Dev Kit.

That’s all there is to it.

The hidden complexity of Hot Reload

Hot Reload is a problem that’s significantly harder than it first appears. We’d made a couple of attempts before this one and were never entirely satisfied with the result. One engineer's earlier prototype was, in his own words, a failed project, and he summarised it as hot reload being simultaneously simpler and far more difficult than he’d realised.

Most XAML hot reload solutions build their own transport. Microsoft’s XET (the implementation behind WPF, WinUI and MAUI) serialises a list of XAML actions in the IDE and ships them to an agent in the app, so no XAML is ever parsed on the device. HotAvalonia, the community option, does IL manipulation and injection via MonoMod and Cecil.

That approach works, and it has served its users well, but we didn’t feel it could deliver the experience we wanted. Patching IL at runtime means depending on a long list of Avalonia internals that were never designed to be depended upon, so every method we rename or move risks breaking it. It also leans on dynamic code generation, which puts it at odds with AOT and with the mobile targets we care about. As the people who own the framework, we’d rather make Avalonia itself hot-reload friendly and build on supported foundations than reach in and rewrite our own internals from the outside.

How it works

Rather than inventing another bespoke TCP stack, we build on .NET Hot Reload. Microsoft has invested heavily in it for .NET MAUI, including Android and iOS support in .NET 11, which we inherit for free. Standardising on the runtime's own toolset lets us focus on the Avalonia side and avoid adding more tooling for you to install.

Save an .axaml file, and the agent works out what changed and applies it to the running app. C# edits, such as a view model change, land in the same motion, so they're visible without renavigating.

Where possible, the change is applied to the specific element you edited, so its state survives and nothing around it is rebuilt. The logs tell you what happened for each change. It's early days; some edits will still fall back to a full reload of the element, which resets the view's context.

I even produced a demo of it reloading the shell of an Avalonia-based Wayland compositor. If you can hot reload an operating system's UI, your settings page should be fine!

Pricing and availability

AvaloniaUI.DiagnosticsSupport.HotReload is a licensed Avalonia package, available now on NuGet. It’s covered by the Avalonia Plus, Pro and Enterprise tiers, and as promised, everyone on the legacy Accelerate plan receives it too. If you already hold a licence for Charts, TreeDataGrid, Markdown or Media Player, you’re already covered; grab the key from the customer portal and add it to your app.

It isn’t included in the community tier. If you’d like to try it, start a 30 day trial of Avalonia Pro.

The road ahead

This release is a foundation, with a solid engine underneath it that we'll keep extending.

Some of us have shipped hot reload before, and the lesson from that work was that the bugs which matter only show up in customers' real apps, never in simple samples. Take it for a spin and tell us what breaks. That feedback is what'll shape the next release.