16

When I create a new, clean Blazor .NET 6.0 app and start it (using Visual Studio 2022), I see the following error in the browser console:

WebSocket connection to 'ws://localhost:60908/BlazorApp3/' failed: (aspnetcore-browser-refresh.js:234)

Error in browser console

Does anyone else have this and any idea if this is a VS2022 bug and how to fix it?

Tim
  • 14,999
  • 1
  • 45
  • 68
Mcanic
  • 1,304
  • 16
  • 22
  • Have you enabled Web Socket support in IIS? – Grizzlly Nov 20 '21 at 19:44
  • Thank you, I tried adding UseWebsockets() in program.cs, but I have the same error in the browser console when using either IIS or Kestrel. Looks like this bug https://github.com/dotnet/aspnetcore/issues/34975 is still not resolved. Or else I am missing something?? – Mcanic Nov 21 '21 at 21:24
  • go to Turn Windows Features on and off > Internet Information Services > World Wide Web Services > App Development Features > Enable WebSocket Protocol. Does this work? – Grizzlly Nov 22 '21 at 18:08
  • Switching off "Enable Hot Reload and Edit and Continue when debugging" seemed to resolve this issue for me. However, I feel that is probably using a hammer to crack a nut. As others have suggested, it could be related to IIS Express/Kestrel Web Sockets. – m-smith Nov 24 '21 at 09:24
  • I tried your suggestions (enabled Web Sockets in IIS) but it does not work. The error still appears (same when starting it using Kestrel). I think it's a bug related Hot Reload / Edit & Continue, I hope it will be fixed in a future update of VS2022... I have reported this to Microsoft through the Visual Studio feedback pages. – Mcanic Nov 26 '21 at 12:42

2 Answers2

4

I had exactly the same issue after installing Visual Studio 2022. I tried to "Enable WebSocket Protocol" but that didn't work. However, the fix for me was to change Script Debugging to "Enabled".

Hopefully, this can help you too.

Vitali Karmanov
  • 157
  • 1
  • 5
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30941780) – tomerpacific Feb 04 '22 at 06:10
  • 1
    Well, enabling script debugging did help me, although I can still see the `WebSocket failed to connect.` error. I guess that with debugging enabled, Visual Studio falls back to some other means of communication to accomplish hot reload. – White hawk Apr 25 '22 at 19:01
0

The same issue has been discussed here https://developercommunity2.visualstudio.com/t/WebSocket-connection-to-wss:-fail/1670519?q=ERR_CONNECTION_RESET&ftype=problem&space=8&stateGroup=active&sort=newest and the fix is available with VS 17.2 Preview 2.1

Jaish Mathews
  • 766
  • 1
  • 9
  • 25