【问题标题】:How can i stop getting exceptions on my app service when I turn on Application Insights in Azure on a web app service?在 Web 应用服务上打开 Azure 中的 Application Insights 时,如何停止在我的应用服务上出现异常?
【发布时间】:2022-10-13 15:16:16
【问题描述】:

我在 Azure 中有一个应用服务,它是一个 web 应用程序,asp.net v4.7。 当我打开 Application Insights 时,我不断收到错误消息,

Exception: The type initializer for 'PerTypeValues`1' threw an exception.
Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, 
Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its 
dependencies. The system cannot find the file specified.

关于如何阻止这种情况发生的任何想法?

【问题讨论】:

  • 您是否能够在本地构建和运行您的应用程序?
  • 你想做什么,修复错误或忽略异常并阻止它被记录?
  • 想解决这个问题,因为我需要启用应用程序洞察力进行监控。否则,应用洞察的意义何在?

标签: azure-web-app-service


【解决方案1】:

要将 Application Insights 添加到 ASP.Net 4.7.2,请按照以下步骤操作。

  • 右键单击Project文件夹 =>Add=>Application Insights Telemetry=> Application Insights Sdk(本地)并完成后续步骤。

  • Application InsightsApplicationInsights.config 相关的 NuGet 包将添加到项目中。

  • 在 Azure 门户中,创建Application Insights并复制ConnectionString并粘贴到ApplicationInsights.config 连接字符串部分。

部署应用程序并打开Application Insights在门户中。

输出:

'PerTypeValues`1' 的类型初始值设定项引发了异常。 无法加载文件或程序集“System.Runtime.CompilerServices.Unsafe, 版本=4.0.4.1,文化=中性,PublicKeyToken=b03f5f7f11d50a3a' 或其之一 依赖关系。该系统找不到指定的文件。

  • 检查是否添加了System.Runtime.CompilerServices.Unsafe的更新版本。

确保您的 .csproj 文件夹包含以下参考

 <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
   <HintPath>packagesSystem.Runtime.CompilerServices.Unsafe.4.5.3lib
et461System.Runtime.CompilerServices.Unsafe.dll</HintPath>
 </Reference>

要打开.csproj 文件,请右键单击项目文件夹并选择Unload Project。确保再次单击Reload Project

【讨论】:

    猜你喜欢
    • 2021-06-01
    • 2021-07-03
    • 1970-01-01
    • 2023-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多