---
title: "Hot reload a C# UI template while the app runs"
url: https://recursiveai.org/oneapp/cookbook/hot-reload-csharp-ui-template/
description: "Save a OneApp HTML template in a running .NET Debug app and update the window without restarting or losing text already typed into a field."
version: "1.2.1"
---

```shell
dotnet add package RecursiveAI.OneApp
dotnet add package RecursiveAI.OneUI
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.


Save this edit to `NotesPage.html` while the Debug app runs.

```html
<h1 id="heading">Draft notes</h1>
```

[The example](https://recursiveai.org/oneapp/cookbook/hot-reload-csharp-ui-template/hot-reload-csharp-ui-template.zip) is the full program below: unzip it and `dotnet run`.

The heading becomes **Draft notes** without clearing the text you typed in **Draft**.

## Full program

The zip contains a .NET 10 console project, `Program.cs` and `NotesPage.html`. If starting from a new console project, also install the template compiler:

```shell
dotnet add package RecursiveAI.OneUI
```
The OneUI package compiles `NotesPage.html` into the other half of the `NotesPage` partial class. Put both files next to the project file if building it by hand.

`NotesPage.html` starts with a heading and a text field:

```html
<main style="padding: 24px">
  <h1 id="heading">Notes</h1>
  <label for="note">Draft</label>
  <input id="note" />
</main>
```

`Program.cs`:

```csharp
using OneApp;

using var host = AppHost.Create(new AppOptions(new NotesPage())
{
    Title = "Notes",
    Width = 420,
    Height = 240,
});
host.Run();
public partial class NotesPage { }
```

Start the app, type **Call the editor** in **Draft**, then save the heading change shown above. On Linux the same window stayed open, its heading read **Draft notes**, and **Call the editor** remained in the focused field. The terminal printed:

```text
[oneapp reload] applied: template updated in place
```

If a save introduces a markup error, the app keeps the last working screen and reports the error in the terminal; fix the line it names and save again.

![Notes window after reload, showing Draft notes and Call the editor in the text field](https://recursiveai.org/oneapp/images/hot-reload-csharp-ui-template/reloaded.png)

## Variations

Add a plain paragraph after the heading. As with the heading edit, this doesn’t need a new C# handler or expression:

```html
<p>Keep this draft open.</p>
```

## Related recipes

- [Build a desktop app with HTML and CSS in C#](https://recursiveai.org/oneapp/cookbook/build-desktop-app-with-html-css/)
- [Install the OneApp dotnet new template](https://recursiveai.org/oneapp/cookbook/install-oneapp-dotnet-new-template/)

## The short answer

In a native OneApp Debug app, run the project and save the component’s `.html` file. You don’t have to stop and relaunch the app to change a label or add simple markup. The running process can apply a template that uses only expressions, handlers, and components it already knows about. That’s why the example changes what you see without discarding what you typed. A template that needs new C# code can’t use this path.

## Does `dotnet run` hot reload a OneApp template?

Yes. In a Debug build, the app watches its own project files. The same native watcher works whether you start it from the terminal or an IDE. Edit the source file in the project directory, not a copy under `bin` or `obj`. Components in referenced projects don’t belong to that watcher; rebuild after changing one. If you copy the built app away from its sources, it has nothing to watch there.

## What’s the difference between hot reload and a restart?

An in-place reload rebuilds the component’s UI nodes from the new template, not the application binary. The component keeps its state, focused element, typed text, and scroll positions. Keep the text field in the template if your goal is to try a new layout while preserving a draft.

An edit that introduces a handler or component the running build doesn’t know about needs a new build. A C# source edit also takes that path. After a successful build, the new process gets back text, number, and Boolean component state, as well as typed field text and focus; lists and other state are rebuilt by the new code. A build error leaves the old app running. See the [hot reload docs](https://recursiveai.org/oneapp/docs/hot-reload/) for the full list of edits and what each does.

## Why isn’t hot reload working when I save?

First, check that the app is running in Debug, not Release. The default Release build doesn’t include the watcher. In Debug, check whether `ONEAPP_RELOAD` is set to `0` or the project overrides `OneAppHotReload` to `false`. Then check that you saved a changed file inside the app’s own project. Saving unchanged text does nothing. If the heading still hasn’t changed, read the terminal: a parser or compiler diagnostic points to the edit that couldn’t be applied.
