启动Aspire AppHost无法访问问题排查
分类: Aspire开发 ◆ 标签: #分布式开发 #云应用开发 #Asp.Net core基础 ◆ 发布于: 2025-02-17 17:58:08

最近在学习.Net Aspire
时遇到一个非常奇怪的问题:使用.Net runtime
启动AppHost
之后,AppHost
正常启动,但是访问AppHost DashBoard
出现一片空白,同时从控制台观察到报如下的错误:
fail: Aspire.Hosting.Dashboard.Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'ym1plIUVhrxgKiN9V_NeCNpiWRAVTUkV9RNyE3vhE14'.
Microsoft.JSInterop.JSException: Could not find 'window.getWindowDimensions' ('getWindowDimensions' was undefined).
Error: Could not find 'window.getWindowDimensions' ('getWindowDimensions' was undefined).
at https://localhost:17154/_framework/blazor.web.js:1:537
at Array.forEach ()
at l.findFunction (https://localhost:17154/_framework/blazor.web.js:1:505)
at b (https://localhost:17154/_framework/blazor.web.js:1:5248)
at https://localhost:17154/_framework/blazor.web.js:1:3041
at new Promise ()
at y.beginInvokeJSFromDotNet (https://localhost:17154/_framework/blazor.web.js:1:3004)
at gn._invokeClientMethod (https://localhost:17154/_framework/blazor.web.js:1:62730)
at gn.processIncomingData (https://localhost:17154/_framework/blazor.web.js:1:60119)
at connection.onreceive (https://localhost:17154/_framework/blazor.web.js:1:53760)
at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
at Aspire.Dashboard.Components.Resize.BrowserDimensionWatcher.OnAfterRenderAsync(Boolean firstRender) in //src/Aspire.Dashboard/Components/Resize/BrowserDimensionWatcher.cs:line 27
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
尝试使用浏览器的开发者工具进行调试,打开JavaScript
控制台以及网络可以看到:
以及网络的情况:
根据上述的错误信息,我搜遍了所有的网络资料都没有明白具体到底是什么原因导致了这个问题发生,不得已给Aspire
的项目组提交了一个issue
: https://github.com/dotnet/aspire/issues/7592
提交了之后也一直没有回复,过了几天我又开始尝试重现调试这个简单的starter
应用,突然想起来会不会是有某些和Asp.net Core
相关的变量导致了这个问题发生?
赶紧检查了一下系统的变量定义,突然发现之前开发Orchard Core
定义的Asp.net Core
的Web Root
变量明晃晃的定义在了系统变量中:ASPNETCORE_WEBROOT
, 关于可用的环境变量以及Content Root
, 均可以参考文档:
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/webapplication?view=aspnetcore-9.0 https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/web-host?view=aspnetcore-9.0
移除上述特定的环境变量之后,重启启动Aspire AppHost
问题缓解。