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

.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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.08 11:33:10