加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Web API项目在部署时不会运行 – 无法加载文件或程序集’N

发布时间:2020-12-15 17:49:16 所属栏目:百科 来源:网络整理
导读:我在部署MVC 5 WEB API项目时遇到此错误: 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. 我已经按照t
我在部署MVC 5 WEB API项目时遇到此错误:

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.

我已经按照this并重新安装NuGet包“Update-Package Newtonsoft.Json -Reinstall”但它没有用.

有谁在这里有任何想法可能会出错?

解决方法

检查对Newtonsoft.json DLL的引用,并确保它没有自动选择解决方案中packages文件夹之外的版本.

我的VS 2013一直在各种/程序文件(x86)/ …文件夹中查找其他副本.它甚至忽略了将包版本DLL显式添加到项目中.不得不深入挖掘,找出为什么会发生这种情况……

调查

我在文本编辑模式下打开了项目.csproj文件,并搜索了对Newtonsoft.Json的所有引用.

事实证明我没有一个,但两个引用我的csproj文件中的DLL(我不知道这是可能的).一个引用较旧的Newtonsoft.json 5.0.6(当前为5.0.8).

我没有手动删除其中一个,而是将这个缺少的元素添加到第二个DLL包含中.我还将版本号更改为5.0.8:

<Private>True</Private>

所以它现在看起来像:

<Reference Include="Newtonsoft.Json,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed,processorArchitecture=MSIL">
  <HintPath>....CsQueryTestpackagesNewtonsoft.Json.5.0.8libnet45Newtonsoft.Json.dll</HintPath>
  <Private>True</Private>
</Reference>

Private是为DLL引用定义“Copy Local”的设置.然后它再次开始将DLL包含在输出中!

我将弄清楚要从csproj文件中删除哪个,但是现在如果遇到这个问题,这可能会让你开始.看起来原因可能是过去的NUGET更新.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读