项目中使用到了Blazor Web Assembly,之前启动调试都正常,会默认打开我的Chrome浏览器,欢乐的跑着,突然有一天启动调试时报错:Cannot connect to the target at localhost:5001: Could not connect to debug target at http://localhost:9222: Promise was canceled.

这个错误整整光了两个小时在全网找解决方案,然而前不满意,其中一个比较接近的答案如下:
https://www.gitmemory.com/issue/microsoft/vscode-js-debug/775/703945845

我的最终解决方案如下:

常见原因

  • 调试端口被占用:Chrome 调试端口(默认 9222)已被其它进程占用。
  • 浏览器进程残留:关闭全部 Chrome 进程(含后台)后重试。
  • launchSettings.json 中的端口与浏览器调试配置不一致。
  • 杀毒软件或代理拦截了本地回环端口。

处理建议

  • 结束所有 chrome.exe 进程,必要时重启 VS。
  • 核对 Properties/launchSettings.json 的 applicationUrl 与调试端口。
  • 临时换用其它浏览器或 Edge 调试通道,验证是否为浏览器侧问题。

相关阅读

参考资料

💰 此内容为付费阅读 请先登录