首页 > 解决方案 > 无法加载文件或程序集“System.Runtime.InteropServices”

问题描述

我在我的 .NetFramework 4.6.2 项目中引用了一个针对 .NetStandard 和 .NetFramework 的 nuget 包。作为一个依赖,这个 nuget 包安装System.Runtime.InteropServices包。但是现在当我尝试通过浏览器访问我的服务时,我收到了这个错误: Could not load file or assembly 'System.Runtime.InteropServices, Version=4.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)

花了 3 个多小时试图修复这个问题。有人有任何修复吗?

这是我引用的 nuget 包:https ://github.com/wavefrontHQ/wavefront-opentracing-sdk-csharp

这是我的Web.config样子:

        <assemblyIdentity name="System.Runtime.InteropServices" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
      </dependentAssembly>
      <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>

标签: c#.netcom-interop.net-standard.net-standard-2.0

解决方案


您可以尝试删除下面的 web.config 条目。

<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>

编辑:一些用户确认此方法适用于无法加载文件或程序集'System.Runtime.InteropServices.RuntimeInformation


推荐阅读