无法在干净的 autofac.mv5 安装中加载文件或程序集 System.Runtime.CompilerServices.Unsafe

问题描述

我刚刚在我的 autofac.Mvc5 6.0 安装中安装了 .net framework 4.7.2

除了添加 nuget 包之外没有添加任何代码,我收到此错误

无法加载文件或程序集 System.Runtime.CompilerServices.Unsafe,版本=4.0.6.0, Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a 或其中之一 依赖。找到的程序集的清单定义不匹配 大会参考。 (来自 HRESULT 的异常:0x80131040)

有人知道吗?

解决方法

您可能有另一个使用不同版本的 System.Runtime.CompilerServices.Unsafe 的库。 web.config 中有什么?
你试过bindingRedirect吗?

<dependentAssembly>
    <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>

如果您有更新的版本,请在上面的 newVersion 中替换它。