Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use Hot Reload while debugging Blazor WASM (Aspnet hosted)

If I create a new Blazor WASM app, out of the box I can use Hot Reload by running dotnet watch run in a terminal window. This will launch a browser window, and any changes I make will update in the browser automatically.

However, if I start my app in Visual Studio with the debugger attached (F5), I don't get any hot reload functionality. When I make a change, Visual Studio shows a message in the bottom left that says Code Changes were applied successfully, but the browser does not refresh. If I refresh the browser manually, I still do not see my changes.

I have "Hot Reload on Save" checked. Pressing the new Hot Reload button doesn't seem to do anything.

The browser refresh script is injected into my html. <script src="/_framework/aspnetcore-browser-refresh.js"></script>

I am using Visual Studio 2022 Version 17.0.0 Preview 7.0, and dotnet 6 RC 2 (6.0.0-rc.2.21480.10).

Is it not possible to use Hot Reload while debugging a Blazor WASM app, or am I missing something?

like image 441
Dave Avatar asked Nov 03 '21 14:11

Dave


People also ask

Does Blazor have hot reload?

Blazor WebAssembly Hot Reload supports the following code changes: New types. Nested classes. Most changes to method bodies, such as adding, removing, and editing variables, expressions, and statements.

Is Blazor Wasm multithreaded?

NET apps on WebAssembly using Web Workers," Microsoft said today. "This is a new . NET runtime capability. Multithreading support hasn't been integrated yet into Blazor WebAssembly apps (planned for .

How do I turn off hot reload?

The one workaround is to change the “Auto build and refresh option” to None. This will turn off hot reload, but unfortunately it will also disable auto refreshing the browser after build.

How do I clear Blazor WebAssembly cache?

Just press Ctrl+F5 it cleans cache and gets files again.

Is Blazor Wasm a spa?

Blazor WebAssembly is a single-page app (SPA) framework for building interactive client-side web apps with . NET.


1 Answers

Update

This bug has been fixed as of version 17.1 of Visual Studio 2022.


Posterity

This feature is currently unsupported when using the debugger in WebAssembly apps. According to Microsoft:

*In Visual Studio 2022 GA release Hot Reload support for Blazor WebAssembly when using the Visual Studio debugger isn’t enabled yet. You can still get Hot Reload If you start your app through Visual Studio without the debugger, and we are working to resolve this in the next Visual Studio update.

According to Microsoft, this will be fixed in the 17.1 release of VS 2022.

The fix will be included in the 17.1 release.

The latest preview version of Visual Studio 2022 (17.1.0 Preview 2 released Jan 5, 2022) contains the fix for this. I tested this personally and verified it's working. Note that you will still need to wait for 17.1 if you don't want to use the preview channel.

like image 177
Kirk Woll Avatar answered Oct 11 '22 18:10

Kirk Woll