[英]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: 这就是我做的:
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.