blazorblazor-webassembly.net-6.0visual-studio-2022hosted-blazor-webassembly

Hot reload in Visual Sstudio 2022 Current not working for existing Blazor application


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?


Solution

  • 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.