7

After using VS 2022 preview for several iterations I removed it and installed VS 2022 Current when it became available.

Existing Blazor hosted application does not Hot reload on file save or on pressing Hot reload button. It was reloading "fine" in preview versions. It does not matter if I run it with or without debugging.

New application created with newly installed version does Hot reload.

I don't see any important difference in *.csproj or launchSettings.json files. They both target net6.0. I also removed .vs directory and cleaned solution.

Only difference there is is that my projects are using Program.cs and Startup.cs vs only Program.cs in new application template, but that does not matter. Or, does it?

What is preventing Visual Studio from Hot reloading existing application?

UPDATE

Switching to single Program.cs and WebApplication builder did help somewhat. Now hot reload works without debugging. With debugging VS says it applied changes but they are not applied on screen.

Still I would like to know why is this change necessary and how to enable Hot reload while debugging?

vernou
  • 6,818
  • 5
  • 30
  • 58
Milan
  • 969
  • 2
  • 16
  • 34
  • I installed Visual Studio 2022 and .NET 6 yesterday. Hot reloading work with Blazor Server, but don't work (for me) with Blazor WebAssembly. – vernou Nov 14 '21 at 17:03
  • Can you specify the Blazor type (server/wsam) of your applications? – vernou Nov 14 '21 at 17:04
  • I wrote hosted. It is WASM hosted. The thing is that when I create new application from VS Hot Reload works. I even noticed that VS changes Output window to shot output from Hot Reload once app starts. In the case of existing app Output window stays at Debug. I makes me believe that there must be something somewhere in project or solution or launchSettings.json file although I was not able to recognize it. – Milan Nov 15 '21 at 19:12
  • It does NOT work. I have been testing for hours on latest 6.0.100 , Blazor wasm and latest updated VS2022. – Greg Dec 13 '21 at 19:34

1 Answers1

4

For your issue, currently Blazor WebAssembly only supports hot reload when not debugging. This is kind of documented here: https://learn.microsoft.com/en-us/aspnet/core/test/hot-reload?view=aspnetcore-6.0

In Visual Studio 2022 GA (17.0), Hot Reload is only supported when running without the debugger.

I found your Q while trying to diagnose why my own existing Blazor WebAssembly ASP.Net Core hosted app wouldn't hot reload and after 4-5 hours of trying all sorts of things I finally found that there was a project reference to a class library that still targeted .NET 5. In my case this reference was no longer required, removing it fixed my issues and my Hot Reload output once again showed.

(Web assembly): Hot reload session started

From my testing if any referenced .NET 6 project in turn references a .NET 5 project this brought that dependency into the mix too and needed to be removed or upgraded.

TheDuke
  • 185
  • 1
  • 2
  • 12
  • I am testing a pure .net 6.0.100 Blazor wasm project ( from the template ) and Hot Reload does NOT work running on Blazor wasm with CRTL F5 - it never works. It never has. Tested using VS Code and VS 2022. – Greg Dec 13 '21 at 19:32
  • I have the same problem. Blazor WASM template project does not hot reload with regular F5 debugging. Must use CTRL-F5 – ChiliYago Dec 28 '21 at 23:05