Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot Reload nearly always fails, with Blazor WebAssembly and "dotnet watch" #45519

Closed
1 task done
szalapski opened this issue Dec 9, 2022 · 53 comments · Fixed by dotnet/sdk#31015
Closed
1 task done
Assignees
Labels
area-blazor Includes: Blazor, Razor Components feature-hot-reload This issue is related to the Hot Reload feaature investigate
Milestone

Comments

@szalapski
Copy link

szalapski commented Dec 9, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Please get Hot Reload to work reliably and consistently with Blazor WebAssembly, especially with changes to .razor files. This feature seems so buggy when it should "just work". It seems to work much better with non-Blazor server-side changes, e.g. to a Web API, but that's not where much productivity benefit would result.

When using dotnet watch on my Server project, with verbose logging , I get watch : Hot reload capabilities: . (not even Baseline) and, on a change, No hot reload changes to apply. (when there are). This is with .NET 7.0.0 and SDK 7.0.100 on a solution that was created with .NET 6 and recently upgraded to 7.

Starting...
dotnet watch 🔥 Hot reload capabilities: .
dotnet watch ⌚ File changed: .\MySoln\Client\Shared\MainLayout.razor.
dotnet watch ⌚ No deltas modified. Applying changes to clear diagnostics.
dotnet watch ⌚ Received 1 from browser in [Count: 1, MessageType: Binary, EndOfMessage: True].
dotnet watch ⌚ No hot reload changes to apply.
dotnet watch 🔥 Hot reload change handled in 4092.6926ms.

When running from VS (with or without debugging), I get similar output:
image, or sometimes instead "Your debugged process might be corrupted and restarting it is recommended nearly always."

The most relevant issue seems to be #40587, but there must be much more to that one that isn't working right.

See also:

Seems like there are a lot of others struggling too but not commenting in GitHub issues, e.g.

Expected Behavior

  • dotnet watch hot reload should just work. I don't want to see "No hot reload changes to apply."
  • If it isn't working and thus I get "watch : Hot reload capabilities: .", I'd like to see output that tells me why in the verbose output (indeed, perhaps even in warnings).

.NET Version

7.0.0

Anything else?

dotnet --info

.NET SDK:
Version: 7.0.100
Commit: e12b7af219

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19044
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.100\

Host:
Version: 7.0.0
Architecture: x64
Commit: d099f075e4

.NET SDKs installed:
5.0.408 [C:\Program Files\dotnet\sdk]
6.0.403 [C:\Program Files\dotnet\sdk]
7.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

@TanayParikh TanayParikh added area-blazor Includes: Blazor, Razor Components feature-hot-reload This issue is related to the Hot Reload feaature labels Dec 10, 2022
@Stuart88
Copy link

Stuart88 commented Dec 11, 2022

Hot Reload is just terrible.

I feel bad criticising any of this because in the end it's a 'free' framework that most of us haven't helped to develop, but...

There is absolutely no point in allowing and/or promoting the existence of hot reload in its current state. It is rubbish, useless, pointless. Every little change (and sometimes no change at all) requires a rebuild. It isn't 'hot reload' AT ALL.

@szalapski
Copy link
Author

I don't feel bad, but I hope my criticism is constructive and optimistic. I want to help, too, but no idea how I can, as there is no clue as to what is wrong when Hot Reload fails.

For what it's worth, I wouldn't mind so much an automatic rebuild--my main concern in this issue is that I get No hot reload changes to apply. or Your debugged process might be corrupted and restarting it is recommended nearly always.

@szalapski szalapski changed the title Hot Reload still isn't reliable or consistent with Blazor WebAssembly and "dotnet watch" Hot Reload nearly always fails, with Blazor WebAssembly and "dotnet watch" Dec 11, 2022
@MackinnonBuck
Copy link
Member

Thanks for sharing this feedback. We are aware that there are a number of issues with hot reload we are trying to address. In order for us to address the issue you're facing, could you please provide a repro project hosted as a public GitHub repo that demonstrates the problem?

@MackinnonBuck MackinnonBuck added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Dec 12, 2022
@ghost
Copy link

ghost commented Dec 12, 2022

Hi @szalapski. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@danroth27
Copy link
Member

@tmat @lambdageek

@danroth27
Copy link
Member

This is with .NET 7.0.0 and SDK 7.0.100 on a solution that was created with .NET 6 and recently upgraded to 7.

@szalapski Have you tried cleaning out the bin and obj folders and rebuilding?

@szalapski
Copy link
Author

szalapski commented Dec 12, 2022

@danroth27 Yes, but I just tried it again to be sure. Deleted bin and obj in all three projects (Server, Client, Shared), and ran dotnet watch --project on the server project. No change:

Starting...
dotnet watch 🔥 Hot reload capabilities: .
dotnet watch ⌚ File changed: .\MySoln\Client\Shared\MainLayout.razor.
dotnet watch ⌚ No deltas modified. Applying changes to clear diagnostics.
dotnet watch ⌚ Received 1 from browser in [Count: 1, MessageType: Binary, EndOfMessage: True].
dotnet watch ⌚ No hot reload changes to apply.
dotnet watch 🔥 Hot reload change handled in 4092.6926ms.

@MackinnonBuck, I'll try to get a example project up ASAP.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Dec 12, 2022
@szalapski
Copy link
Author

@MackinnonBuck , here's the minimal example as requested.

https://github.com/szalapski/HotReloadIssue45519Demo

Clone this and run

dotnet watch --verbose --project ./TradeCars/Server

The site should start up. You'll see Hot reload capabilities: . which portends the failure. Edit anything in Index.razor to watch hot reload fail.

@mkArtakMSFT
Copy link
Member

@tmat given the repro is provided, I'm assigning this to you to investigate. Thanks!

@mkArtakMSFT mkArtakMSFT removed the Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. label Dec 13, 2022
@mkArtakMSFT mkArtakMSFT added this to the .NET 8 Planning milestone Dec 13, 2022
@ghost
Copy link

ghost commented Dec 13, 2022

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@szalapski
Copy link
Author

szalapski commented Dec 13, 2022

Thanks for investigating...I must say, I think this should be targeted for a more urgent fix release for .NET 7, as it was supposed to be working in .NET 6.

@Contengo
Copy link

Contengo commented Jan 7, 2023

We have been working with Blazor for three years now, but are seriously contemplating switching everything to React solely because of this issue. The development experience is beyond painful - it would be better to switch the feature off and set the expectation that you always have to recompile. It's the "waiting to see if it works, knowing it probably won't" that kills all motivation and enthusiasm.

@szalapski
Copy link
Author

@tmat, I'm curious if you are able to reproduce with that repo.

@enantiomer2000
Copy link

I 100% have this issue. It makes development very slow unfortunately =(

@danroth27
Copy link
Member

I did a few quick tests with 7.0.101 and VS 17.4.3:

  • .NET 6 + Blazor WebAssembly hosted + dotnet watch => ✅ Work
  • .NET 7 + Blazor WebAssembly standalone + dotnet watch => ✅ Works
  • .NET 7 + Blazor WebAssembly hosted + Visual Studio => ✅ Works
  • .NET 7 + Blazor WebAssembly hosted + dotnet watch => ❌ Broken ☹️
dotnet watch ⌚ File changed: C:\Users\user\Desktop\BlazorApp\Client\Pages\Index.razor.
dotnet watch ⌚ No hot reload changes to apply.

This is being investigated.

@jacksonsfaria
Copy link

For me is always No hot reload changes to apply
:(

@Andreas02-dev
Copy link

I've managed to get hot reload working for .NET 6 and .NET 7 Blazor WebAssembly using dotnet watch.

I use VS Code DevContainers, and the following command works for me: DOTNET_USE_POLLING_FILE_WATCHER=true dotnet watch --project ./web.csproj

Please note that I use the following base image: mcr.microsoft.com/devcontainers/dotnet:7.0-jammy, which results in dotnet --version 7.0.102.

Targeting .NET 6, DOTNET_USE_POLLING_FILE_WATCHER=true dotnet watch is sufficient for hot reload to work.
Targeting .NET 7, DOTNET_USE_POLLING_FILE_WATCHER=true dotnet watch --project ./web.csproj is needed, otherwise dotnet watch ⌚ no hot reload changes to apply. will be returned.

I hope this helps someone else struggling here.

@Stuart88
Copy link

I've managed to get hot reload working for .NET 6 and .NET 7 Blazor WebAssembly using dotnet watch.

I use VS Code DevContainers, and the following command works for me: DOTNET_USE_POLLING_FILE_WATCHER=true dotnet watch --project ./web.csproj

Please note that I use the following base image: mcr.microsoft.com/devcontainers/dotnet:7.0-jammy, which results in dotnet --version 7.0.102.

Targeting .NET 6, DOTNET_USE_POLLING_FILE_WATCHER=true dotnet watch is sufficient for hot reload to work.
Targeting .NET 7, DOTNET_USE_POLLING_FILE_WATCHER=true dotnet watch --project ./web.csproj is needed, otherwise dotnet watch ⌚ no hot reload changes to apply. will be returned.

I hope this helps someone else struggling here.

Honestly, doesn't help at all.

It should just work. No need for hacky convoluted workarounds.

@szalapski
Copy link
Author

szalapski commented Feb 8, 2023

@Andreas02-dev , thanks for the tip, though it didn't help for me either. I still get Hot reload capabilities: . even though I set the environment variable DOTNET_USE_POLLING_FILE_WATCHER to "true".

This is being investigated.

@danroth27, thanks for doing that. Any learnings from the investigation yet?

@Andreas02-dev
Copy link

Andreas02-dev commented Feb 8, 2023

@szalapski

Yeah, it can be a bit spotty sometimes.

From personal experience, re-running the command a few times usually does the trick.

Sometimes, it'll 'apply' the changes (but it won't) so you'll need to run the command again.

I'm afraid I don't currently know how to make it work in your case, but I do hope they will
~ a) improve hot reload, as it's a bit of a mess right now
~ b) someone can help you figure out how to at least get hot reload working somewhat.

@brianpursley
Copy link

brianpursley commented Mar 3, 2023

For me, hot reloading works for a very simple new Blazor Server project out of the box, but does not work on the much larger, more complex, real-world project that I worked on.

I tried so many things to try to get hot reloading to work, and what finally allowed it to work was installing version 4.5.0 of the Microsoft.CodeAnalysis.Common Nuget package. Something my project had referenced was implicitly installing version 4.4.0 of this package, and I guess for some reason, that one doesn't work with hot reloading (?). I hope this helps someone else who might have the same problem.

(I'm using .NET version 7.0.201 by the way)


I almost forgot, this seems to be important too. My launchSettings.json looks like this:

I found that I had to have "launchBrowser": true in order for hot reloading to work, even though I would prefer not to have it launch:

{
  "profiles": {
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Watch": {
      "commandName": "Executable",
      "executablePath": "dotnet",
      "commandLineArgs": "watch",
      "workingDirectory": "$(ProjectDir)",
      "applicationUrl": "https://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

EDIT: So here I am 5 days later on 3/8/2023, and hot reloading no longer works for me, even with this "fix". At best it is inconsistent I guess. It is very frustrating not knowing what causes it not to work 😞

@thepigeonfighter
Copy link

I am throwing my hat in the ring. This problem has been plaguing me for months. Blazor WASM .NET7 in VS 20222 Version 17.5.3. Often getting the "No hot reload changes to apply.". The problem happens both in dotnet watch and using VS.

@dodyg
Copy link

dodyg commented Apr 2, 2023

  • Visual Studio 17.5.3
  • Create a new Web Assembly project
  • Add one simple page (no data access, nothing, just static text).
  • Adding simple thing such as a field or a property on @code section will often generate this kind of error.

run


  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.4" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.4" PrivateAssets="all" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Shared\TalyBNPLBlazor.Shared.csproj" />
  </ItemGroup>

</Project>

@Stuart88
Copy link

Stuart88 commented Apr 2, 2023

  • Visual Studio 17.5.3

    • Create a new Web Assembly project

    • Add one simple page (no data access, nothing, just static text).

    • Adding simple thing such as a field or a property on @code section will often generate this kind of error.

run


  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.4" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.4" PrivateAssets="all" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Shared\TalyBNPLBlazor.Shared.csproj" />
  </ItemGroup>

</Project>

If you add a new property it's gonna need to recompile.

But there are still plenty of times when it wants to recompile even though it shouldn't. For example, changing a value assignment on something that is already compiled, i.e. 'Edit and Continue' which is pretty much the thing that is failing in such a case, and has failed in various ways for years already, even before Blazor came about.

I really wish Microsoft would fix this, or at least explain why it's not possible to do so.

@dodyg
Copy link

dodyg commented Apr 2, 2023

If you add a new property it's gonna need to recompile.

Hmm ok. So under what scenarios should Hot Reload works on Razor Web Assembly?

@Stuart88
Copy link

Stuart88 commented Apr 2, 2023

If you add a new property it's gonna need to recompile.

Hmm ok. So under what scenarios should Hot Reload works on Razor Web Assembly?

The one thing that should work every time is when you modify the mark-up of any component.

There are probably some underlying complexities to that, but the way hot reload is advertised, I would expect any update to propagate into the UI without needing to stop debugging.

There is also the aforementioned 'Edit and Continue' which has been a thing in .NET for a very long time. It's more temperamental nowadays.

@danroth27
Copy link
Member

danroth27 commented Apr 2, 2023

If you add a new property it's gonna need to recompile.

Hmm ok. So under what scenarios should Hot Reload works on Razor Web Assembly?

@dodyg @Stuart88 With Blazor WebAssembly the runtime is much more limited with it's hot reload capabilities. It can basically only do method body replacement for a limited set of cases. We are working on expanding the set of edits supported, which is tracked here: dotnet/runtime#57365. You can look at the tracking issue to get an idea of what is current supported and what we're working on adding.

Even so the VS error dialog @dodyg is seeing looks wrong. It says there is a compilation error when there isn't one being reported in the output window. If you make an edit that isn't supported by hot reload and you need to rebuild then it should show a different dialog saying precisely that. @Stuart88 Could you please create a VS feedback ticket for that error using the Report a Problem tool in VS? We should investigate what's going on there. It would be great if you could see if the same error dialog is shown with the 17.6 previews.

@Stuart88
Copy link

Stuart88 commented Apr 2, 2023

@danroth27

That error dialog is not my screenshot.

With Blazor WebAssembly the runtime is much more limited with it's hot reload capabilities

The currently advertised functionality sounds pretty good to me, and presumably is better on VS 17.6, so perhaps my complaints around hot reload are already resolved. Will give it a test run soon

@jacksonsfaria
Copy link

  • Visual Studio 17.5.3

    • Create a new Web Assembly project
    • Add one simple page (no data access, nothing, just static text).
    • Adding simple thing such as a field or a property on @code section will often generate this kind of error.

run


  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.4" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.4" PrivateAssets="all" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Shared\TalyBNPLBlazor.Shared.csproj" />
  </ItemGroup>

</Project>

If you add a new property it's gonna need to recompile.

But there are still plenty of times when it wants to recompile even though it shouldn't. For example, changing a value assignment on something that is already compiled, i.e. 'Edit and Continue' which is pretty much the thing that is failing in such a case, and has failed in various ways for years already, even before Blazor came about.

I really wish Microsoft would fix this, or at least explain why it's not possible to do so.

Sometimes it also happens when changing only one class="bg-write" for example... it seems that after a long time with vs open it always happens, I close and open VS and it works again. But it's already much better than a few months ago.

@danroth27
Copy link
Member

That error dialog is not my screenshot.

Whoops, my bad. Fixed in my comment.

@dodyg
Copy link

dodyg commented Apr 3, 2023

I close and open VS and it works again. But it's already much better than a few months ago.

@jacksonsfaria what version of VS are you running?

@jacksonsfaria
Copy link

Microsoft Visual Studio Community 2022 (64 bits) - Versão 17.5.2
But in the previous version (17.5.2) I already felt an improvement.

@marek-safar
Copy link
Contributor

We landed another wave of Hot Reload improvements in .NET 8 P1 that ships with Visual Studio 2022 v17.6 Preview 2. It'd be great to hear if you still experience recompilation instead of hot-reloads in this version.

@lonix1
Copy link
Contributor

lonix1 commented Apr 4, 2023

So we need to wait until November for the fixes? Would it be possible to release before then?

@danroth27
Copy link
Member

@lonix1 I believe @marek-safar is referring to work we have done for .NET 8 that enables more hot reload capabilities for Blazor WebAssembly apps so that they are on par with what CoreCLR supports. This means that some cases that previously required a rebuild should now work with hot reload. However, this work doesn't address cases where hot reload fails due to unknown errors or doesn't recognize that a change needs to be applied. These later cases are bugs that we expect to patch as soon as we can track down and address the underlying issues.

@dodyg
Copy link

dodyg commented Apr 6, 2023

@Stuart88

If you add a new property it's gonna need to recompile.

Hot reload on ASP.NET Core Preview 3 and Visual Studio 17.6.0 Preview 2.0 works fine with addition of new properties

@tmat
Copy link
Member

tmat commented Apr 19, 2023

Likely fixed by dotnet/sdk#31015. Please file a new issue if the problem persists in .NET 7.0.3xx

@szalapski
Copy link
Author

szalapski commented Apr 19, 2023

I assume I can't get the 7.0.3xx preview and have to wait a bit? I can't see links for a 7.0.3xx preview anywhere--I can only find for the 8.0 preview.

@tmat
Copy link
Member

tmat commented Apr 19, 2023

8.0.100-preview.3.23178.3 also has the fix.

@szalapski
Copy link
Author

OK, thanks, I'm going to wait for the 7.0.3xx SDK to test, as that is what my team will use till .NET 8 release.

@wf-soft
Copy link

wf-soft commented Apr 22, 2023

I use a Bootstrap Blazor framework, and my CSS cannot be hot overloaded, it seems to be easily disturbed,

After installing. net 8, my blazer project must add

<UseRazorSourceGenerator>false</UseRazorSourceGenerator>

to start, and any hot overloads will fail

@jadenrogers
Copy link

When will 7.0.3xx SDK be released?

@szalapski
Copy link
Author

szalapski commented Jun 5, 2023

it was not fixed. I wish someone would have tested it with the provided example before deeming it "likely fixed". The test is very easy.

Here's the minimal example, the same one that was provided in #45519, now upgraded to use SDK 7.0.302

szalapski/HotReloadIssue45519Demo

Clone this and run

dotnet watch --verbose --project ./TradeCars/Server

The site should start up. You'll see Hot reload capabilities: . which portends the failure. Edit anything in Index.razor to watch hot reload fail.

As requested, I have piggybacked on the same issue in 7.0.302 at #47836

@ghost ghost locked as resolved and limited conversation to collaborators Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components feature-hot-reload This issue is related to the Hot Reload feaature investigate
Projects
None yet
Development

Successfully merging a pull request may close this issue.