Hot Reload

The Uno Platform Hot Reload feature provides a way to modify the XAML and C# of your running application, in order to iterate faster on UI or code changes. This makes the inner developer loop faster.

Features

  • Supported in Visual Studio 2022 (Windows) and VS Code (Linux, macOS, Windows, CodeSpaces, and GitPod)
  • XAML and C# Markup Hot Reload for iOS, Catalyst, Android, WebAssembly, Skia (Gtk, WPF and Framebuffer)
  • All C# of Hot Reload in both Visual Studio and VS Code (supported code changes).
  • Simulator and physical devices support
  • What can be Hot Reloaded:
    • XAML files in the main project, in shared projects, and referenced projects libraries
    • C# Markup controls
    • Bindings
    • Full x:Bind expressions
    • AppResources.xaml and referenced resource dictionaries
    • DataTemplates
    • Styles
    • Extensible State restoration
    • Support for partial tree hot reload, where modifying a UserControl instantiated in multiple locations will reload it without reloading its parents

Hot Reload features vary between platforms and IDE, you can check below the list of currently supported features.

How to use Hot Reload

  • Setup your environment by following our getting started guides.
  • Start your application (with or without the debugger, depending on the supported features below)
  • Make changes to your XAML or C# code, save your file then press the red flame icon in the toolbar or use Alt+F10
Important

Using .NET 8 or later (net8.0 in the TargetFrameworks property) is required for Hot Reload to be available when your solution contains iOS, Android, Mac Catalyst or WebAssembly project heads. On Windows, Visual Studio 17.8 or later is required.

Supported features

Skia-based targets provide support for full XAML Hot Reload and C# Hot Reload. There are some restrictions that are listed below:

  • The Visual Studio 2022 for Windows support is fully available, with and without running under the debugger
  • The VS Code Uno Platform extension does not support Hot Reload (C# or XAML) when running with a debugger
  • Adding new C# or XAML files to the project is not yet supported for VS Code

Troubleshooting

Common issues

  • Observe the application logs, you should see diagnostics messages in the app when a XAML file is reloaded.
  • The file named RemoteControlGenerator\RemoteControl.g.cs in the analyzers node for your project contains the connection information, verify that the information host addresses and the port number.
  • WinAppSDK on Windows-specific issues
  • If you're getting ENC0003: Updating 'attribute' requires restarting the application, add the following in the Directory.Build.props (or in each csproj project heads):
    <PropertyGroup>
      <!-- Required for Hot Reload (See https://github.com/unoplatform/uno.templates/issues/376) -->
      <GenerateAssemblyInfo Condition="'$(Configuration)'=='Debug'">false</GenerateAssemblyInfo>
    </PropertyGroup>
    
  • if you're getting the Unable to access Dispatcher/DispatcherQueue error, you'll need to update your app startup to Uno 5 or later:
    • Add the following lines to the shared library project csproj file :
      <ItemGroup>
          <PackageReference Include="Uno.WinUI.DevServer" Version="$UnoWinUIVersion$" Condition="'$(Configuration)'=='Debug'" />
      </ItemGroup>
      
      Note

      If your application is using the UWP API set (Uno.UI packages) you'll need to use the Uno.UI.DevServer package instead.

    • Then, in your App.cs file, add the following:
      using Uno.UI;
      
      //... in the OnLaunched method
      
      #if DEBUG
              MainWindow.EnableHotReload();
      #endif
      

Visual Studio 2022

  • Make sure that C# Hot Reload is not disabled in Visual studio
    • Open Tools / Options
    • Search for .NET / C++ Hot Reload
    • Ensure that all three check boxes are checked (Enable hot reload when deugging, Enable Hot Reload without debugging and Apply Hot Reload on File Save))
  • Hot Reload for WebAssembly is not supported when using the debugger. Start your app using Ctrl+F5.
  • The output window in VS has an output named Uno Platform in its drop-down. Diagnostics messages from the VS integration appear there.
  • When a file is reloaded, XAML parsing errors will appear in the application's logs, on device or in browser.
  • If there are multiple versions of the Uno.WinUI Package present in the solution, the newest will be used, regardless of the started application
  • The app does not update its XAML, because the port number in RemoteControl.g.cs is 0.
    • Ensure you have the latest version of the Visual Studio extension installed.
    • Rebuild the app until the number is different than zero.

VS Code

  • The output window in Code has an output named "Uno Platform - Hot Reload" in its drop down. Diagnostics messages from the extension appear there.
  • Hot Reload for WebAssembly and Skia+GTK/WPF is not supported when using the debugger. Start your app using Ctrl+F5.
  • Depending on your machine's performance, the hot reload engine may take a few moments to initialize and take your project modifications into account.
  • Make sure that the selected project in the status bar is not the solution file, but rather the project platform you are debugging.
  • If Hot Reload does not function properly, you can try using the Developer: Reload Window command in the palette (using Ctrl+Shift+P)
  • When working on Skia+Gtk apps, make sure to start the app without the debugger, and make sure that in the debugger tab, the Skia.Gtk (Debug) target selected.