VS 2022 for Mac中Blazor WASM应用断点无法激活问题
问题解决:Blazor WASM在VS 2022 for Mac中代码后置文件断点无法触发
问题场景
在VS 2022 for Mac开发Blazor WASM应用,程序可正常构建并启动调试,但Razor页面的.razor.cs代码后置文件中设置的断点始终显示为空心圆圈,无法触发调试。启用详细日志后,终端输出以下错误:
[14:43:46] fail: DevToolsProxy[0] failed: Microsoft.WebAssembly.Diagnostics.DebuggerAgentException: SendDebuggerAgentCommand failed for GetMethodFromToken: [Result: IsOk: False, IsErr: True, Value: , Error: { "result": { "type": "object", "subtype": "error", "className": "ReferenceError", "description": "ReferenceError: getDotnetRuntime is not defined at <anonymous>:1:1", "objectId": "8838028629078804716.1.3" }, "exceptionDetails": { "exceptionId": 2, "text": "Uncaught", "lineNumber": 0, "columnNumber": 0, "scriptId": "7", "stackTrace": { "callFrames": [ { "functionName": "", "scriptId": "7", "url": "", "lineNumber": 0, "columnNumber": 0 } ] }, "exception": { "type": "object", "subtype": "error", "className": "ReferenceError", "description": "ReferenceError: getDotnetRuntime is not defined at <anonymous>:1:1", "objectId": "8838028629078804716.1.4" } } } ] at Microsoft.WebAssembly.Diagnostics.MonoSDBHelper.SendDebuggerAgentCommand[T](T command, MonoBinaryWriter arguments, CancellationToken token, Boolean throwOnError) at Microsoft.WebAssembly.Diagnostics.MonoSDBHelper.GetMethodIdByToken(Int32 assembly_id, Int32 method_token, CancellationToken token) at Microsoft.WebAssembly.Diagnostics.MonoProxy.SetMonoBreakpoint(SessionId sessionId, String reqId, SourceLocation location, String condition, CancellationToken token) at Microsoft.WebAssembly.Diagnostics.MonoProxy.SetBreakpoint(SessionId sessionId, DebugStore store, BreakpointRequest req, Boolean sendResolvedEvent, Boolean fromEnC, CancellationToken token) at Microsoft.WebAssembly.Diagnostics.MonoProxy.OnSourceFileAdded(SessionId sessionId, SourceFile source, ExecutionContext context, CancellationToken token) at Microsoft.WebAssembly.Diagnostics.MonoProxy.LoadStore(SessionId sessionId, Boolean tryUseDebuggerProtocol, CancellationToken token) at Microsoft.WebAssembly.Diagnostics.MonoProxy.LoadStore(SessionId sessionId, Boolean tryUseDebuggerProtocol, CancellationToken token)
解决方案
- 启用WebAssembly调试开关:右键项目→属性→调试,勾选启用WebAssembly调试,并确认调试目标为Chrome/Firefox等兼容浏览器。
- 清理编译缓存:执行
dotnet clean命令,或手动删除项目根目录下的bin和obj文件夹,再重新构建项目。 - 确保调试符号生成:右键项目→属性→生成→调试符号,选择完整或便携式,禁止选择“无”,确保调试模式下符号文件正常生成。
- 重置VS调试组件:关闭VS for Mac,删除
~/Library/Application Support/Microsoft/VisualStudio/17.0/LocalInstall/Addins路径下的WebAssembly相关缓存文件,重启VS后重试调试。 - 更新浏览器并禁用干扰插件:确保使用的浏览器为最新版本,调试时关闭隐私模式、广告拦截器等可能干扰调试代理连接的插件。
内容的提问来源于stack exchange,提问作者Clay Hess
相关产品推荐
相关产品推荐

