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

dotnet 9, "dotnet watch" is really bad in Blazor Server #45810

Closed
qucee98 opened this issue Jan 9, 2025 · 25 comments
Closed

dotnet 9, "dotnet watch" is really bad in Blazor Server #45810

qucee98 opened this issue Jan 9, 2025 · 25 comments
Labels
Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch untriaged Request triage from a team member

Comments

@qucee98
Copy link

qucee98 commented Jan 9, 2025

Environment:

  • OS: Linux Ubuntu 24.04.1 LTS
  • IDE: Vim/Neovim (non vscode and visual studio IDE)
  • SDK: 9.0.200-preview.0.24575.35
  • LSP: Omnisharp

hot reloading just sucks in dotnet 9 when using Blazor Server... 🤷‍♂️

I migrated my project from .net 8 to .net 9 and followed this doc:

dotnet watch command seems to be inconsistent in reloading the page when making changes to my current buffer.
When it starts to NOT work, then it never works after any changes, i have to restart the project manually.

".NET 9.0.200" patched it a bit, but hot reloading is still inconsistent in reloading the changes.
#44912
#45749
#45097
#45131

"Hot Reloading"? more like "Hot Mess".

Switching back to .NET 8 until y'all get your stuff together....

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch untriaged Request triage from a team member labels Jan 9, 2025
@XorZy
Copy link

XorZy commented Jan 9, 2025

It would be nice if Microsoft could acknowledge this problem and provide a clear ETA for the fix.
As it stands hot reload, which I would argue is essential when working with Blazor apps, is completely broken.
I have to restart the application every time I make the slightest of changes.
NET 9 was first released almost two months ago now, and I don't understand why fixing this issue is not a priority.

@stephajn
Copy link

It's just as awful in Blazor WASM projects too. Without any other code changes besides updating to .NET 9 and targeting .NET 9 in our projects, Hot Reload went from being something we could depend on and be reliable, to a hot garbage mess that barely functions, even in an ASP.NET Core Web API project, but is especially awful in Blazor projects.
Response from Microsoft has been lackluster, and even almost non-existent with some talks about pushing back fixing it to the .NET 10 milestone which is beyond insane to wait a whole year to fix something that they broke horribly.

Sad to say it, but we just might have to give .NET 9 a pass and go back to .NET 8 if this isn't resolved soon.

@willdean
Copy link

I'm going to add a me-too, because we all know there's nothing motivates MS quite like a thousand-post Github issue...

This is a blocker on 9 as far as we're concerned and I'm really disappointed that yesterday's release (representing ~17% of the whole release cycle) has failed to make a difference. TBH, looking in from outside via GH, the whole dotnet project looks poorly, but Blazor particularly so.

At least there's a bright side - if we don't move to 9 because of dotnet watch, then at least we don't get caught up in all that static-assets insanity...

@breakingram
Copy link

Same... I've noticed that I've been manually restarting the Blazor Server a lot more frequently in 9.

@aaronsmithuk
Copy link

Same. Have been test upgrading and downgrading for weeks now. Come on MS - surely you have the budget to fix one of the most core parts of the MS Dev experience- hot reload!

@danroth27 save us!

@aaronsmithuk
Copy link

aaronsmithuk commented Jan 15, 2025

Just for reference this worked perfectly in .NET 8 (Blazor server and client components in a razor page project) - file save pushed hot reload in about 1 second.
Upgraded to .NET 9 - (v17.12.4 visual studio ent) - when saving it says "file deleted" - then, nothing! Can't upgrade till this is fixed.

"Watch": {
  "commandName": "Executable",
  "executablePath": "C:\\Program Files\\dotnet\\dotnet.exe",
  "commandLineArgs": "watch run -c $(Configuration)",
  "workingDirectory": "$(ProjectDir)",
  "launchUrl": "https://localhost:5001;http://localhost:5000",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
}

@aaronsmithuk
Copy link

Using Visual Studio IIS hot reload in .NET 9 - click save, count to 200 and you might get an update. What is happening here!!

@danroth27
Copy link
Member

@phil-allen-msft @tmat

@aaronsmithuk @qucee98 @breakingram @willdean @XorZy @stephajn Are you still seeing problems with .NET SDK 9.0.102 that released earlier this week? Note that the corresponding 9.0.200 preview update hasn't shipped yet, but should be available later this month.

@willdean
Copy link

Are you still seeing problems with .NET SDK 9.0.102 that released earlier this week? Note that the corresponding 9.0.200 preview update hasn't shipped yet, but should be available later this month.

Yes. It seems about the same as before. (Blazor Server, .NET8 project)

@stephajn
Copy link

stephajn commented Jan 16, 2025

@danroth27 I just updated to the new 9.0.102 SDK yesterday, and updated all of my NuGet packages to the 9.0.1 versions today.

I tried it out with something that we commonly do and immediately the same old problems sprang up.

I have a standalone Blazor WASM project that I will call ProjectA. It references another Razor class library project that I will call ProjectShared, along with other class library projects etc.

With hot reload enabled via running dotnet watch I made a change in a .razor file in ProjectA. Hot reload went into action, and this was the output I got.

dotnet watch ⌚ File added: .\Pages\Accounting\TaxReceiptsList.razor~
dotnet watch ⌚ File updated: .\Pages\Accounting\TaxReceiptsList.razor
dotnet watch ⌚ File added: .\Pages\Accounting\TaxReceiptsList.razor~
dotnet watch ⌚ File updated: .\Pages\Accounting\TaxReceiptsList.razor
dotnet watch ⌚ Unable to apply hot reload, restart is needed to apply the changes.
dotnet watch ❌ Microsoft.CodeAnalysis.Razor.Compiler\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Pages_Accounting_TaxReceiptsList_razor.g.cs(722,177): error ENC0053: Changing the parameters of lambda requires restarting the application.
dotnet watch ❌ Microsoft.CodeAnalysis.Razor.Compiler\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Pages_Accounting_TaxReceiptsList_razor.g.cs(741,122): error ENC0053: Changing the parameters of lambda requires restarting the application.

And this is fair. It's what .NET 8 called a "rude edit". So of course it asked me what I wanted to do going forward, so I selected to always restart when needed.

❔ Do you want to restart your app? Yes (y) / No (n) / Always (a) / Never (v)
❔ a

Using launch settings from C:\source\ProjectA\Properties\launchSettings.json...
dotnet watch ⌚ The file watcher observing 'C:\source\ProjectShared' encountered an error: Too many changes at once in directory:C:\source\ProjectShared.

Except that no changes were made at all in that project. I made a change in literally one .razor file in ProjectA.

After a short time, the application finished restarting, and uselessly opened up a new tab in my browser rather than reloading the existing tab I had open like .NET 8 used to do. Every time the application has to restart it opens a new tab. This is also a completely useless behaviour to me because I want to stay in the tab I was using, and I want to stay on the page I was using rather than starting up from the home page of my application.

Also, this business described above of "too many changes at once" in a project where no change was made is something that only started in .NET 9. We never encountered this in .NET 8.

This is just one behaviour I have seen in .NET 9 in Blazor development when it comes to hot reload.

For even simpler changes like changing a button colour, it can take 30 - 60 seconds for hot reload to apply these changes.

I should also note that I am using Windows 11 Pro on an Intel i7-12700K with 32 GB of RAM and a 1 TB SSD, so I definitely can't blame my system for being underpowered, especially since none of this was a problem on .NET 8.

Also, I'm developing using the latest Chrome. I have also tried Edge to see if there is any difference in hot reload changes being applied and it is just as unreliable.

I hope that this helps.

@stephajn
Copy link

@danroth27 I wanted to give you even more feedback at the server layer regarding Hot Reload. This is for an ASP.NET Core Web API project also running on .NET 9. (Perhaps a different team / issue is needed, but I'm not sure)

Added a new server endpoint on an existing Web API Controller while dotnet watch was running. When hot reload kicked in, this is what the console outputted. For the same of this sample, I am calling the API project "SomeProjectName.Api" and the controller's .cs file is named "SomeApiController.cs"

dotnet watch ⌚ File added: .\Controllers\SomeApiController.cs~
dotnet watch ⌚ File updated: .\Controllers\SomeApiController.cs
dotnet watch ⌚ File added: .\Controllers\SomeApiController.cs~
dotnet watch ⌚ File updated: .\Controllers\SomeApiController.cs
dotnet watch ⚠ [SomeProjectName.Api (net9.0)] Expected to find a static method 'ClearCache' or 'UpdateApplication' on type 'Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlAttributePropertyHelper, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' but neither exists.
dotnet watch 🔥 [SomeProjectName.Api (net9.0)] Hot reload succeeded.

Again, I hope that this is helpful or useful to you.

@danroth27
Copy link
Member

@willdean @stephajn Thanks for these additional details.

@phil-allen-msft @tmat Do we know what's going on here?

@tmat
Copy link
Member

tmat commented Jan 16, 2025

Sounds like multiple potential issues. Any repro with the latest 9.0.2xx build?

@tmat
Copy link
Member

tmat commented Jan 16, 2025

dotnet watch ⚠ [SomeProjectName.Api (net9.0)] Expected to find a static method 'ClearCache' or 'UpdateApplication' on type 'Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlAttributePropertyHelper, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' but neither exists.

This is fixed by dotnet/aspnetcore#58558 in 10.0 preview.

@stephajn
Copy link

dotnet watch ⚠ [SomeProjectName.Api (net9.0)] Expected to find a static method 'ClearCache' or 'UpdateApplication' on type 'Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlAttributePropertyHelper, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' but neither exists.

This is fixed by dotnet/aspnetcore#58558 in 10.0 preview.

Any chance of back-porting it to .NET 9?

@stephajn
Copy link

Sounds like multiple potential issues. Any repro with the latest 9.0.2xx build?

@tmat I don't have a repro available to recreate this issue, sorry. I could see if I can put something together though.

@Juulsn
Copy link

Juulsn commented Jan 17, 2025

I'm also adding a me-too. Using it in combination with aspire. I do know this won't be supported until 9.0.2xx but the fact that it worked way better in .NET 8 than in .NET 9 is disappointing.
Also had multiple problems in non-aspire context.

Aspire support was why I was ok with using the 9.0.2xx daily builds and since about 1 week it's actually usable now.
However I still see problems like non-reloading of some files without any information in the console, it even says it was successful.

Did open a issue on the sdk repo about this. #45197

@MeikelLP
Copy link

MeikelLP commented Jan 17, 2025

I have this issue in .NET 8 + .NET 9

[App (net8.0)] Expected to find a static method 'ClearCache' or 'UpdateApplication' on type 'Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlAttributePropertyHelper, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' but neither exists.

Hot reload worked fine before .NET 6 with Rider, since it's an "official" feature it's not longer working ever. All my colleagues distrust the "Apply Changes" and restart their aspnetcore app every time which makes development very slow. Especially if you just edit a razor (HTML) file.

I tried dotnet watch but I get the warning stated here which is probably the root cause. Very sad to see such a required feature be handled so poorly by Microsoft. Especially in the times of tools like Vite.

@XorZy
Copy link

XorZy commented Jan 20, 2025

@phil-allen-msft @tmat

@aaronsmithuk @qucee98 @breakingram @willdean @XorZy @stephajn Are you still seeing problems with .NET SDK 9.0.102 that released earlier this week? Note that the corresponding 9.0.200 preview update hasn't shipped yet, but should be available later this month.

It appears hot reload of scoped CSS works better in 9.0.102 but overall it still is very slow and crashes often with this error message.

Unhandled exception. System.ArgumentException: The renderer does not have a component with ID 0.
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetRequiredComponentState(Int32 componentId)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.<RenderRootComponentsOnHotReload>b__53_0()
   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<InvokeAsync>g__Execute|8_0(ValueTuple`3 state)
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderRootComponentsOnHotReload()
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

dotnet watch ❌ [(net9.0)] Change failed to apply (error code: ''). Further changes won't be applied to this process.

dotnet watch ❌ [(net9.0)] Exited with error code 134

@tmat
Copy link
Member

tmat commented Jan 20, 2025

@XorZy Could you please provide repro steps? Ideally in a new issue.

@ArgoZhang
Copy link

ArgoZhang commented Jan 21, 2025

@XorZy same issue

C:\Users\Argo\src\BootstrapBlazor\src\BootstrapBlazor.Server>dotnet watch run
dotnet watch 🔥 Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload.
  💡 Press "Ctrl + R" to restart.
Using launch settings from C:\Users\Argo\src\BootstrapBlazor\src\BootstrapBlazor.Server\Properties\launchSettings.json...
Building...
info: Longbow.Tasks.TaskServicesFactory[0]
      01/21/2025 14:32:00 +08:00: TaskServicesFactory StartAsync() Started
info: Longbow.Tasks.TaskServicesFactory[0]
      01/21/2025 14:32:00 +08:00: TaskServicesManager DefaultScheduler(Clear Upload Files) Created
info: Longbow.Tasks.TaskServicesFactory[0]
      01/21/2025 14:32:00 +08:00: SchedulerProcess Start(methodCall) success Called Elapsed: 00:00:00.0002896
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5053
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Users\Argo\src\BootstrapBlazor\src\BootstrapBlazor.Server
dotnet watch ⌚ File deleted: .\Components\Components\Header.razor.css
dotnet watch 🔥 Hot reload of scoped css succeeded.
dotnet watch ⌚ No hot reload changes to apply.
dotnet watch ⌚ File deleted: .\Components\Components\Header.razor.css
dotnet watch 🔥 Hot reload of scoped css succeeded.
dotnet watch ⌚ No hot reload changes to apply.
dotnet watch ⌚ File added: .\Components\Components\wqwd5rja.5h3~
dotnet watch ⌚ File deleted: .\Components\Components\Header.razor

dotnet watch ⏳ Waiting for a file to change before restarting dotnet...
dotnet watch ❌ System.ArgumentException: An item with the same key has already been added. Key: C:\Users\Argo\src\BootstrapBlazor\src\BootstrapBlazor\BootstrapBlazor.csproj
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at Microsoft.DotNet.Watcher.Tools.IncrementalMSBuildWorkspace.UpdateProjectConeAsync(String rootProjectPath, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.Program.RunAsync()
dotnet watch ❌ An unexpected error occurred

@brettzook
Copy link

I've seen regressions in dotnet watch as well after updating to Visual Studio 17.12.3. If I understand correctly, this also installed 9.0.101 of the dotnet sdk, which is now being used when I run the dotnet CLI command.

Hot Reload sometimes work, maybe 50% of the time for things that are not of the "rude edit" variety.

But I want to highlight something that @stephajn mentioned:

After a short time, the application finished restarting, and uselessly opened up a new tab in my browser rather than reloading the existing tab I had open like .NET 8 used to do. Every time the application has to restart it opens a new tab. This is also a completely useless behaviour to me because I want to stay in the tab I was using, and I want to stay on the page I was using rather than starting up from the home page of my application.

I see the same behavior, even in the simplest WASM standalone project. This behavior really interrupts the development loop, as it means closing the old browser tab, going to the new one, and re-opening browser DevTools, in addition to being dropped in the home page of the app rather than the one I was working on.

I've created a separate issue for this behavior: #46175

@ArgoZhang
Copy link

ArgoZhang commented Jan 23, 2025

The good news is that dotnet sdk 9.0.200-preview.0.25057.12 version works fine. But a new warning is shown

Expected to find a static method 'ClearCache' or 'UpdateApplication' on type 'Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlAttributePropertyHelper, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' but neither exists

info: Longbow.Tasks.TaskServicesFactory[0]
      01/23/2025 10:20:18 +08:00: TaskServicesFactory StartAsync() Started
info: Longbow.Tasks.TaskServicesFactory[0]
      01/23/2025 10:20:18 +08:00: TaskServicesManager DefaultScheduler(Clear Upload Files) Created
info: Longbow.Tasks.TaskServicesFactory[0]
      01/23/2025 10:20:18 +08:00: SchedulerProcess Start(methodCall) success Called Elapsed: 00:00:00.0004551
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5053
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Users\Argo\src\BootstrapBlazor\src\BootstrapBlazor.Server
dotnet watch ⌚ File updated: .\Components\Components\Header.razor
dotnet watch ⚠ [BootstrapBlazor.Server (net9.0)] Expected to find a static method 'ClearCache' or 'UpdateApplication' on type 'Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlAttributePropertyHelper, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' but neither exists.
dotnet watch 🔥 [BootstrapBlazor.Server (net9.0)] Hot reload succeeded.

@danroth27
Copy link
Member

dotnet watch ⚠ [SomeProjectName.Api (net9.0)] Expected to find a static method 'ClearCache' or 'UpdateApplication' on type 'Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlAttributePropertyHelper, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' but neither exists.

This is fixed by dotnet/aspnetcore#58558 in 10.0 preview.

Any chance of back-porting it to .NET 9?

@stephajn Yes, the back port to .NET 9 is in the works here: dotnet/aspnetcore#59908

@danroth27
Copy link
Member

We believe the original issue reported here is fixed in the latest preview release of .NET SDK 9.0.200, which is available with the latest preview of Visual Studio 17.13. A stable release of 9.0.200 should be available in a few weeks.

We expect to address warning about the missing ClearCache or UpdateApplication methods in the 9.0.201 patch release, which is expected in March.

We'll follow up on the other separate issues reported here in their corresponding GitHub issues.

Thanks for your patience, folks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests