c# - 无法加载文件或程序集“System.Runtime.InteropServices.RuntimeInformation”

标签 c# azure azure-application-insights webjob interopservices

每当我尝试使用应用程序洞察和 Entity Framework 运行 webjob 项目时,我都会收到此错误。

System.IO.FileLoadException: 'Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

我已经安装了以下nuget包

Microsoft.Azure.WebJobs.Logging.ApplicationInsights 版本 2.1.0-beta4

Microsoft.Extensions.Logging 版本 2.0.0

Microsoft.Extensions.Logging.Console 版本 2.0.0。

这一切都适用于新的 Visual studio 2017 webjob 项目,当我尝试包含现有代码库(主要使用 Entity Framework )时,我收到此错误。当我查看有效的引用文献时,我没有 System.Runtime.InteropServices.RuntimeInformation,但它已通过 Entity Framework 添加到项目中。它似乎是 .net 标准的一部分,但为什么我的新控制台应用程序不需要 .net 标准!

enter image description here

我不确定为什么它要寻找版本 0.0.0.0,因为我拥有的版本是 4.0.2.0

我也尝试将其添加到项目文件中,但这不起作用。

<PropertyGroup>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
   <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

任何帮助将不胜感激

非常感谢

最佳答案

确认 dwilliss 的上述评论也对我有用。解决方案是摆脱:

<dependentAssembly>
  <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>

(在我的例子中,来自 app.config,用于 Windows 服务。)我的项目仅间接依赖于 System.Runtime.InteropServices.RuntimeInformation。它是我导入的 NuGet 包的依赖项。

关于c# - 无法加载文件或程序集“System.Runtime.InteropServices.RuntimeInformation”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48520188/

相关文章:

c# - 使用 RSA 公钥解密使用 RSA 私钥加密的字符串

c# - 扩展 EF DBContext

azure - 更新 documentDb 更改的搜索索引

azure - 无法让嵌套的 StartOperation 显示在筛选器下拉列表中

c# - 为 Azure Function (v3) 的 RequestTelemetry 添加自定义属性

c# - 使用C#在字符串中的适当位置插入特殊字符

c# - 在 Ubuntu 上禁用证书验证

azure - 根据 Azure 数据工厂中的文件名将文件从一个文件夹复制到多个文件夹

azure - Azure 耐用实体的大小限制是多少