.NET 8应用部署后Application Insights触发System.Diagnostics.PerformanceCounter程序集未找到异常的问题求助
.NET 8应用部署后Application Insights触发System.Diagnostics.PerformanceCounter程序集未找到异常的问题求助
各位好,我最近在给我的.NET 8应用集成Application Insights,本地Windows机器上测试一切正常,但部署到服务器后就触发了未处理异常,具体报错如下:
Unhandled exception. System.TypeInitializationException: The type initializer for 'Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.Implementation.PerformanceCounterUtility' threw an exception. System.IO.FileNotFoundException: Could not load file or assembly 'System.Diagnostics.PerformanceCounter, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. File name: 'System.Diagnostics.PerformanceCounter, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' at Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.Implementation.PerformanceCounterUtility..cctor()
我已经尝试手动安装了System.Diagnostics.PerformanceCounter这个NuGet包,而且确认部署后的文件夹里确实存在对应的.dll文件,但问题还是没解决。另外我也检查了依赖关系,ApplicationInsights的包确实引用了v6.0.0版本的PerformanceCounter包,但不知道为什么部署后就是无法加载。这里有个截图能看到这个依赖关系(显示ApplicationInsights依赖System.Diagnostics.PerformanceCounter v6.0.0)。
我添加Application Insights的代码是这样的:
builder.Services.AddApplicationInsightsTelemetry(options => { options.ConnectionString = builder.Configuration["ApplicationInsights:ConnectionString"]; options.EnableAdaptiveSampling = true; // Optional: reduces telemetry data volume });
有没有大佬能帮忙分析下这到底是怎么回事?或者可能的问题原因是什么?多谢了!
内容来源于stack exchange
相关产品推荐
相关产品推荐

