8

With a fresh install of Windows 11 (in case it matters) and a fresh install of Visual Studio 2022 release (not preview) new Blazor WASM projects (the default template) hot reload works fine.

On the same machine, same version Visual Studio, a project upgraded from 5 to 6 (including all nuget packages).... no hot reload. The button is active, you can click it, it flashes and looks like something should be happening, but the browser does not update at all.

I have checked that all projects are re-targeting .Net 6. The application actually runs just fine.

I am NOT running with Debugging, as I understand that Debugging + WASM + Hot Reload does not work.

Has anyone had success upgrading from .Net 5 to .Net 6 and getting Hot Reload to work? Is there some critical step I'm missing?

Kevon
  • 984
  • 8
  • 28
  • i would suggest you create a minimal repo – Dbl Nov 16 '21 at 20:40
  • @Dbl Thanks for the suggestion, but given that this is with an existing (large) production solution with 20+ projects, I'm not sure that I can do that, both for the amount of work and also for the intellectual property restrictions. – Kevon Nov 16 '21 at 23:15
  • 2
    I have the same issue as @Kevon. Upgraded a WASM project from .Net 5 to .Net 6, checked all assemblies for updates. I run without debugging and the Hot Reload Output even shows: (Web server): Hot reload session started and (Web assembly): Hot reload session started. However even though the Hot Reload button flashes it seems like it has no communication with the browser. – Jim K Dec 02 '21 at 18:12
  • 2
    Note: the fix for UseResponseCompression below did not work for me. – Jim K Dec 02 '21 at 18:18
  • I have the exact same problem. Please upvote and comment on this VS bug here: https://developercommunity.visualstudio.com/t/Hot-reload-not-working-in-ASPNET-6-MVC/1665894 – Alex from Jitbit Mar 21 '22 at 16:33

2 Answers2

2

It might sound couterintuitive, but in Startup.cs change services.AddControllersWithViews().AddRazorRuntimeCompilation(); to services.AddControllersWithViews(); and remove the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet Package.

Startup.cs change

Michael G
  • 535
  • 4
  • 12
1

https://github.com/dotnet/aspnetcore/issues/28293

in the startup file, it seems the middleware UseResponseCompression() breaks hot reload completely.

This fixes it

#if !DEBUG
            app.UseResponseCompression();
#endif
Kevon
  • 984
  • 8
  • 28