---
title: "Diagnose C# UI template compilation errors"
url: https://recursiveai.org/oneui/cookbook/diagnose-component-template-compile-errors/
description: "Diagnose C# UI template compilation errors in OneUI. Print the file, line, column, and diagnostic ID when an edited HTML template is rejected."
version: "1.2.1"
---

# Diagnose C# UI template compilation errors

**OneUI** is a free, open-source .NET library from Recursive AI for writing UI components in HTML, CSS, and C# that run in native windows on desktops and phones, or in a browser via WebAssembly, with OneApp. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneUI) · [GitHub](https://github.com/recursive-ai-oss/oneui-csharp) · [Docs](https://recursiveai.org/oneui/docs/) · [Download example (.zip)](https://recursiveai.org/oneui/cookbook/diagnose-component-template-compile-errors/diagnose-component-template-compile-errors.zip)

Apply an edited template to a mounted component with `TemplateReload.Apply`. If the edit is rejected, print `result.Diagnostics`.

```shell
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.

```csharp
// note: mounted component; edited: new HTML.
var result = TemplateReload.Apply(
    note, edited, "StatusNote.html");
if (result.Status == TemplateReloadStatus.Rejected)
{
    foreach (var d in result.Diagnostics)
        Console.WriteLine(d);
}
```

[The example](https://recursiveai.org/oneui/cookbook/diagnose-component-template-compile-errors/diagnose-component-template-compile-errors.zip) is the full program below: unzip it and `dotnet run`.

This recipe checks edits applied to a running app. In a normal `dotnet build`, template errors appear in the build output as [OUI diagnostics](https://recursiveai.org/oneui/docs/diagnostics/).

For `style="colour: red"`, the printed diagnostic includes `Id = OUI0101`, `File = StatusNote.html`, `Line = 1`, and `Column = 11`. The full program formats those fields on one line.

## The full program

Save the valid template as `StatusNote.html` next to `Example.cs`. OneUI’s source generator pairs the template with the partial `StatusNote` class. The zip uses an ordinary `PackageReference` to `RecursiveAI.OneUI` `1.2.1`. Run it in Debug (the default) so OneUI includes its template reload data. The sample mounts the original in a `ReferenceDocument` (an in-memory document for testing without a window), then passes the invalid edit as a string. Don’t put the invalid edit on disk in place of the valid template before building this example.

```html
<p>Ready</p>
```

```csharp
using OneUI.Components;
using OneUI.Components.Reference;
using OneUI.HotReload;

var doc = new ReferenceDocument();
var ui = new UiContext(doc);
var note = new StatusNote();
ui.Mount(note);

const string edited = "<p style=\"colour: red\">Ready</p>";
var result = TemplateReload.Apply(note, edited, "StatusNote.html");
Console.WriteLine(result.Status);
foreach (var d in result.Diagnostics)
{
    Console.WriteLine($"{d.File}({d.Line},{d.Column}): {d.Id}: {d.Message}");
}
Console.WriteLine($"Still rendered: {doc.Text("p")}");

public partial class StatusNote;
```

```text
Rejected
StatusNote.html(1,11): OUI0101: CSS property 'colour' is not supported by the renderer; did you mean 'color'?
Still rendered: Ready
```

On `Rejected`, the mounted component stays as it was; use the reported position in the **edited** text to find the error.

## Variations

To apply the correction, change the `edited` string in `Example.cs` as follows. The sample prints `Applied` and no diagnostic lines.

```csharp
const string edited = "<p style=\"color: red\">Ready</p>";
```

## Related recipes

- [Create an HTML component with C# state](https://recursiveai.org/oneui/cookbook/create-html-component-with-csharp-state/)
- [Scope CSS to a component](https://recursiveai.org/oneui/cookbook/scope-css-to-component/)

## The short answer

Call `TemplateReload.Apply` with the mounted component, the edited HTML, and the file path you want in the report. When `Status` is `Rejected`, print each entry in `Diagnostics`. The `Id` identifies the compiler check; `File`, `Line`, and `Column` locate it in the edit; `Message` explains what to fix. Call on the UI thread in a build with template reload enabled.

## How do you find the file, line, and column of a template error?

Read the location from the diagnostic itself, rather than looking for the line of the C# call to `Apply`. In `StatusNote.html(1,11): OUI0101`, the line and column are both one-based, and column 11 is where `colour` begins. If your editor needs a range, the diagnostic also has `EndLine` and `EndColumn`, with the end column just past the error. The optional `sourcePath` parameter labels the location; `Apply` reads the template text you pass it, not that path. When you leave out the path, OneUI uses the path recorded at build time when available.

## How do you fix a compilation error in an edited template?

Start with the message. For `OUI0101`, check the CSS property name and [the supported properties](https://recursiveai.org/oneui/docs/css-support/). Correcting `colour` to `color` makes this edit valid. For other IDs, use the [diagnostic reference](https://recursiveai.org/oneui/docs/diagnostics/) to tell an unrecognized attribute or event from a malformed tag. Reapply the corrected edit and check the status again.

If the status is `NeedsRebuild` instead of `Rejected`, read `Causes`: the running build is missing something the edit now uses, such as a new C# expression. Rebuilding and restarting supplies it. `Unavailable` is different again: check the result’s message to see whether reload support is off or the component isn’t mounted. Neither status means there’s a template compiler error at the reported line.
