blazorwebassemblyhot-reload

.NET 8 blazor wasm hot reload not working


Context: Visual Studio 2022 v17.9.6, .NET 8 (SDK v8.0.204), Blazor Webassembly Hosted solution.

Applying Hot Reload to a non-debugging (CTRL-F5 run) webassembly app ... stopped working. At one time in the past it was working (more so with .NET 7), in a rather flakey way, as one would expect considering the limitations of certain types of edits not being supported. But I'm talking about very simple edits, like changing <p>Hi</p> to <p>Bye</p> in a Razor component.

In my case, it got to the point where every attempt to apply edits via hot reload would result in VS encountering an "Unexpected error" (a ManagedDeltaApplierFailedToConnectException, to be precise) and post the following dialog box:

enter image description here

In other words, Hot Reload is completely broken. What is the fix?


Solution

  • In the index.html file of your client project, inside the <body> tag, near the bottom with the other script tags, add the following

    <environment names="Development">
        <script src="_framework/aspnetcore-browser-refresh.js"></script>
    </environment>
    

    Then,

    1. Close down the client (browser) and server (if using hosted)
    2. Restart VS
    3. Build your solution
    4. Run it (CTRL-F5)
    5. Make a simple HMTL edit
    6. Apply hot reload (ALT-F10) and watch with delight as your edits are applied without the irritating error dialog appearing.