无法加载文件或程序集 - 反射坚持加载旧版本



在Visual Studio(2013)中运行单元测试时出现以下错误。

System.IO.FileLoadException:无法加载文件或程序集"Newtonsoft.Json,版本=6.0.0.0,区域性=中性,公钥令牌=30ad4fe6b2a6aeed"或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(HRESULT的例外:0x80131040)

Newtonsoft.Json 是我引用的一个 DLL。但有趣的是,我在所有地方都引用了Newtonsoft.Json 7.0。我很困惑为什么反射坚持加载旧版本6.0。

关于我可以从哪里开始调查的任何提示?

谢谢

我会检查您的web.config文件,看看是否有引用旧版本的内容。

您也可以尝试在web.config中添加此内容,以确保使用正确的版本。我会把它放在<system.web>标签之后

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
            <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

最新更新