简体   繁体   English

Newtonsoft.Json版本8.0.2无法加载文件或程序集错误

[英]Newtonsoft.Json version 8.0.2 Could not load file or assembly Error

I'm attempting to parse a JSON file in Class Library within an Web API solution. 我正在尝试在Web API解决方案中解析类库中的JSON文件。 It is a regular C# Class Library, not the Portable kind. 它是一个普通的C#类库,而不是Portable类。

I've tried every single answer mentioned here , but it still doesn't work! 我已经尝试过这里提到的每一个答案,但它仍然不起作用! I keep getting the same error which is: 我一直得到同样的错误:

Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. 无法加载文件或程序集'Newtonsoft.Json,Version = 8.0.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed'或其中一个依赖项。 The located assembly's manifest definition does not match the assembly reference. 定位的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040)":"Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed (HRESULT异常:0x80131040)“:”Newtonsoft.Json,Version = 8.0.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed

Here is the code: 这是代码:

public IList<BranchRM> AllBranches()
{
    var result = new List<BranchRM>();
    var dataSourcePath = AppDomain.CurrentDomain.BaseDirectory + "Data/branches.json";
    var dataAsText = File.ReadAllText(dataSourcePath);
    if (string.IsNullOrEmpty(dataAsText)) return result;
    var branchList = JsonConvert.DeserializeObject<List<Branch>>(dataAsText);
    result = AutoMapper.Mapper.Map<List<BranchRM>>(branchList);
    return result;
}

I was fixing some old code in one of my Windows Phone 8 solutions and thought of updating the NuGet packages and was greeted with the same issue. 我在我的一个Windows Phone 8解决方案中修复了一些旧代码,并考虑更新NuGet包,并遇到了同样的问题。

A comment from StivOstenberg here helped me solve this. 从StivOstenberg注释这里帮我解决这个问题。

This is what I did: 这就是我做的:

  1. Removed the NuGet package. 删除了NuGet包。 Just clicked 'Uninstall' from NuGet manager. 只需点击NuGet经理的“卸载”即可。 Make sure to remove it from every project in the solution separately . 确保单独从解决方案中的每个项目中删除它
  2. Clean Solution. 清洁解决方案 Rebuild Solution. 重建解决方案。
  3. Now, remove the using statement from your entire solution! 现在,从整个解决方案中删除using语句! Can be done with a quick find and replace for using Newtonsoft.Json on 'Entire Solution'. 可以快速查找并替换在“整个解决方案”上使用Newtonsoft.Json
  4. Repeat step 2. (Ignore the errors) 重复步骤2.(忽略错误)
  5. Add package again from NuGet manager & build (Ctrl+Shift+B). 再次从NuGet manager&build(Ctrl + Shift + B)添加包。
  6. Finally (almost), for every error shown , go to the particular page and add reference again . 最后(几乎), 对于显示的每个错误 ,转到特定页面并再次添加引用
  7. Repeat step 2 and Run. 重复步骤2和运行。

There might be some redundant steps, but this is exactly what I did, and it worked. 可能有一些冗余的步骤,但这正是我所做的,并且它起作用了。 Hope it helps you too. 希望它也能帮到你。

Make sure there are no conflicting versions of Newtonsoft in a parent assembly! 确保父程序集中没有冲突版本的Newtonsoft!

In a child-assembly I wanted to use Newtonsoft.Json.8.0.3. 在子程序集中,我想使用Newtonsoft.Json.8.0.3。

Well the StartUp project is an MVC5 web app. 那么StartUp项目是一个MVC5网络应用程序。 There I use the BundleTransformer.Less.XXX which had a dependency to Newtonsoft.Json.8.0.2. 在那里我使用BundleTransformer.Less.XXX,它依赖于Newtonsoft.Json.8.0.2。 Upgrading NewtonSoft.Json to 8.0.3 (all the same version now) resolved it for me. NewtonSoft.Json 升级到8.0.3(现在所有版本都相同)为我解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载文件或程序集Newtonsoft.json版本6.0.0.0 - Could not load file or assembly Newtonsoft.json Version 6.0.0.0 无法加载文件或程序集 &#39;Newtonsoft.Json,版本 = 12.0.0.0? - Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0? 无法加载文件或程序集 &#39;Newtonsoft.Json,版本 = 10.0.0.0 - Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0 无法加载文件或程序集 &#39;Newtonsoft.Json,版本 = 7.0.0.0 - Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0 无法加载文件或程序集“Newtonsoft.Json”版本=11.0.0.0 - Could not load file or assembly 'Newtonsoft.Json' Version=11.0.0.0 无法加载文件或程序集'Newtonsoft.Json,版本 = 3.5.0.0 - Could not load file or assembly 'Newtonsoft.Json, Version=3.5.0.0 无法加载文件或程序集“NewtonSoft.Json,版本=12.0.0.0” - Could not load file or assembly 'NewtonSoft.Json, Version=12.0.0.0' 无法加载文件或程序集“ Newtonsoft.Json” - Could not load file or assembly 'Newtonsoft.Json' 无法加载文件或程序集“newtonsoft.json” - could not load file or assembly 'newtonsoft.json' CacheManager.Serialization.Json“无法加载文件或程序集&#39;Newtonsoft.Json,Version = 8.0.0.0” - CacheManager.Serialization.Json “Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM