Reputation: 15307
I'm attempting to parse a JSON file in Class Library within an Web API solution. It is a regular C# Class Library, not the Portable kind.
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. 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
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;
}
Upvotes: 5
Views: 10380
Reputation: 1469
Make sure there are no conflicting versions of Newtonsoft in a parent assembly!
In a child-assembly I wanted to use Newtonsoft.Json.8.0.3.
Well the StartUp project is an MVC5 web app. There I use the BundleTransformer.Less.X.X.X which had a dependency to Newtonsoft.Json.8.0.2. Upgrading NewtonSoft.Json to 8.0.3 (all the same version now) resolved it for me.
Upvotes: 1
Reputation: 164
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.
A comment from StivOstenberg here helped me solve this.
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.
Upvotes: 5