You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Blazor WASM托管项目断点调试失败问题求助

Blazor WASM托管项目调试问题排查思路

问题描述

调试Blazor WASM托管项目时出现运行时错误(截图如下):
Blazor WASM调试错误截图

Server项目的断点可以正常命中,但在Debug->Windows->Modules列表中只能看到Server项目,看不到Client项目,无法调试Client代码。

环境信息

  • Visual Studio 2022 最新版本
  • 基于.NET 9的Blazor WASM托管应用(包含Server、Client、Shared三个项目)

项目配置文件

Server项目 launchSettings.json

{
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
    },
    "IMS5_1.Server": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "dotnetRunMessages": "true"
    },
    "WSL": {
      "commandName": "WSL2",
      "launchBrowser": true,
      "launchUrl": "https://localhost:5001",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "ASPNETCORE_URLS": "https://localhost:5001;http://localhost:5000"
      },
      "distributionName": "Ubuntu",
      "dotnetRunMessages": "true"
    }
  },
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": false,
    "iisExpress": {
      "applicationUrl": "http://localhost:31647",
      "sslPort": 44346
    }
  }
}

Client项目 launchSettings.json

{
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
      "nativeDebugging": true
    },
    "WSL": {
      "commandName": "WSL2",
      "distributionName": ""
    }
  },
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:61992/",
      "sslPort": 44382
    }
  }
}

排查解决思路

  • 确认Client项目调试配置:打开Client项目属性,进入"调试"选项卡,确保Blazor WebAssembly部分勾选了启用调试;托管模式下,可尝试关闭Client的nativeDebugging(Server会代理调试连接)。
  • 清理重建项目:执行Build -> Clean Solution,手动删除所有项目的bin和obj文件夹,再Rebuild Solution,最后重启Visual Studio清除缓存。
  • 检查Server对Client的依赖配置:查看Server项目的.csproj文件,确认存在指向Client的<ProjectReference>,且包含<BlazorWebAssemblyProject>true</BlazorWebAssemblyProject>;同时检查Server的Program.cs是否配置了app.UseStaticFiles()和app.MapFallbackToFile("index.html"),确保能正确提供Client静态文件。
  • 手动附加调试进程:启动项目后,通过Debug -> Attach to Process找到浏览器进程(如chrome.exe),选择"Blazor WebAssembly"调试类型进行附加,尝试触发Client断点。
  • 检查浏览器设置:关闭浏览器隐私模式、禁用所有扩展,避免干扰调试连接;尝试更换浏览器(如Chrome换Edge)排除浏览器兼容性问题。
  • 重置launchSettings配置:Server的inspectUri建议使用默认生成值,手动修改可能导致调试代理连接失败;若端口冲突,修改Server的applicationUrl端口号后重试。

内容的提问来源于stack exchange,提问作者user3656651

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 14:17:33