网络API项目将无法运行时,其部署 - 无法加载文件或程序集“Newtonsoft.Json,版本= 4.5.0.0 [英] Web API project won't run when its deployed - Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0

查看:675
本文介绍了网络API项目将无法运行时,其部署 - 无法加载文件或程序集“Newtonsoft.Json,版本= 4.5.0.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到这个错误,当我部署我的MVC 5 WEB API项目:

I keep getting this error when I deploy my MVC 5 WEB API project:

无法加载文件或程序集Newtonsoft.Json ,版本= 4.5.0.0,
区域性=中性公钥= 30ad4fe6b2a6aeed'或其
依赖关系之一。该系统找不到指定的文件。

Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

我遵循的这个并重新安装的NuGet包更新封装Newtonsoft.Json -Reinstall,但它没有工作。

I have followed this and re-install the NuGet package "Update-Package Newtonsoft.Json -Reinstall" but it didn't work.

有没有人在这里任何想法,有什么可以去错了?

Does anyone have any idea here as to what could be going wrong?

推荐答案

检查参考Newtonsoft.json DLL,并确保它不会自动在您的解决方案选择了一个版本的软件包文件夹之外。

Check the reference to the Newtonsoft.json DLL and make sure it has not automatically chosen a version outside of the packages folder in your solution.

我的VS 2013保持在不同的 /程序文件(x86)/ ... 文件夹寻找其他副本。它被忽略包版本DLL来项目甚至明确加载。必须深入挖掘,找出为什么这发生...

My VS 2013 kept finding other copies in various /program files (x86)/... folders. It was ignoring even an explicit add of the package version DLL to the project. Had to dig deeper to find out why this was happening...

我打开项目 .csproj的文件,在文本编辑模式,并寻找到Newtonsoft.Json所有引用。

I opened the project .csproj file, in text edit mode, and searched for all references to Newtonsoft.Json.

原来我不是一个,而是两个参考DLL在我的csproj文件(我不知道这是可能的)。其中引用的一个旧Newtonsoft.json 5.0.6(目前是5.0.8)。

It turned out I had not one, but two reference to the DLL in my csproj file (I did not know that was possible). One referenced an older Newtonsoft.json 5.0.6 (current was 5.0.8).

相反比手动删除其中的一个,我添加了这个缺少的元素,第二个DLL包容。我也改变了版本号为5.0.8:

Rather than manually remove one of them, I added this missing element to the second DLL inclusion. I also changed the version number to 5.0.8:

  <Private>True</Private>



所以现在看起来像:

so it now looked like:

<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
  <HintPath>..\..\CsQueryTest\packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
  <Private>True</Private>
</Reference>



私人是定义复制设置本地一个DLL参考。然后,它开始了包括再输出的DLL!

Private is the setting that defines "Copy Local" for a DLL reference. It then started including the DLL in the output again!

我会找出哪些从的csproj文件中删除,但现在可能得到,如果你有这个你要去问题。它看起来像的原因可能是一个过去的NuGet更新。

I will figure out which to remove from the csproj file, but for now this may get you going if you have this problem. It looks like the cause may have been a past NUGET update.

这篇关于网络API项目将无法运行时,其部署 - 无法加载文件或程序集“Newtonsoft.Json,版本= 4.5.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆