dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.38k stars 10k forks source link

dotnet watch and Blazor WebAssembly: client makes no attempt to connect to Hot Reload websocket server #47340

Closed mattbruv closed 1 year ago

mattbruv commented 1 year ago

Is there an existing issue for this?

Describe the bug

dotnet watch hot reloading seems to randomly decide if it wants to work or not depending on which way the wind is blowing. Yesterday it was fine, today it is not working at all.

I'm running dotnet watch --project . -v in my project's client directory. On the surface it looks fine:

dotnet watch ⌚ Configuring the app to use browser-refresh middleware.
dotnet watch ⌚ Refresh server running at wss://localhost:61988,ws://localhost:61989.
dotnet watch 🔥 HotReloadProfile: BlazorWebAssembly.

When I edit a .razor file, my browser does not update and I get this output in the terminal only once:

dotnet watch ⌚ File changed: ./Pages/Users.razor.

Then the terminal does nothing until I kill it. Edits after this are not recognized or printed. Only when I press ^C to end the process does it print something:

dotnet watch 🛑 Shutdown requested. Press Ctrl+C again to force exit.
dotnet watch ⌚ Failed to read Hot Reload capabilities: A task was canceled.
  ❔ Do you want to restart your app - Yes (y) / No (n) / Always (a) / Never (v)?
  ❔ dotnet watch ⌚ Caught top-level exception from hot reload: System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Microsoft.Extensions.Tools.Internal.ConsoleRequester.GetKeyAsync(String prompt, Func`2 validateInput, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watcher.Tools.RudeEditDialog.EvaluateAsync(CancellationToken cancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(DotNetWatchContext context, CancellationToken cancellationToken)

When I open my localhost web app and look at the Network tab in Chrome developer tools and filter for WebSocket connections, there are none. The client is not even attempting to connect to the hot reload server, nor are there any errors in my console to go off of. It just seems like it doesn't even try, and I have no idea how I'm supposed to remedy this.

Expected Behavior

The client should make an attempt to connect to the WebSocket Refresh server when dotnet watch is run. The client should communicate with the refresh server and correctly hot reload code on file changes.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

7.0.201

Anything else?

.NET SDK:
 Version:   7.0.201
 Commit:    68f2d7e7a3

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.3
 OS Platform: Darwin
 RID:         osx.12-arm64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.201/

Host:
  Version:      7.0.3
  Architecture: arm64
  Commit:       0a2bda10e8

.NET SDKs installed:
  6.0.406 [/usr/local/share/dotnet/sdk]
  7.0.201 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.14 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.14 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  x64   [/usr/local/share/dotnet/x64]
    registered at [/etc/dotnet/install_location_x64]

Environment variables:
  Not set

global.json file:
  Not found
paleocomburo commented 1 year ago

I have the same problem. Found this issue by Googling the error message.

paleocomburo commented 1 year ago

Deleting all bin/ and obj/ folders inside the solution seems to have fixed it for now...

hereisalex commented 1 year ago

Also having this same problem, also found this issue by Googling the error message. What's the deal?

ghost commented 1 year ago

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimal repro project that illustrates the problem without unnecessary code. Please share with us in a public GitHub repo because we cannot open ZIP attachments, and don't include any confidential content.

ghost commented 1 year ago

Thanks for contacting us.

We're moving this issue to the .NET 9 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.

ghost commented 1 year ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

amirvenus commented 1 year ago

Anybody found a solution?

I get this on the output when running dotnet watch:

Failed to read Hot Reload capabilities: A task was cancelled

tmat commented 1 month ago

@mattbruv @amirvenus Please try the latest .NET 9 preview and file a new issue if you still see problems. We have made significant investments in reliability of dotnet-watch in this release. If you file a new issue, please include the output of dotnet watch --verbose.