Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies
I have a WinJS project that is previously built on Windows 8.1 using VS 2013.
Recently I upgraded this project to Universal Windows 10 by creating a blank Javascript Universal windows 10 project and then added all my files from old project.
I have Windows Runtime Components and also Class Library for SQLite.
I added Universal Windows Runtime Component and Universal Class Library and copied all my files from old project to respective places.
Somehow I managed to remove all the build errors.
I installed all the required SQLite-net, SQLite for Universal Windows Platform, Newtonsoft, etc.
But when I run the application and call a Native method in Windows Runtime Component it gives some kind of strange errors as:
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll but was not handled in user code.
Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
Newtonsoft version is: 9.0.1
My project.json file of Windows Runtime Component has following:
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0",
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
My Visual Studio version is:
I tried removing all the Newtonsoft json and re-installing it but no luck.
Solution 1:
I solved this problem by adding Newtonsoft.Json to the NuGet of the startup project (even though it is not directly used in the startup project).
Solution 2:
I made a basic Demo and reproduced this problem. It seems that WinRT component failed to find the correct assembly of Newton.Json
. Temporarily the workaround is to manually add the Newtonsoft.json.dll
file. You can achieve this by following steps:
Right click References-> Add Reference->Browse...-> Find C:\Users\.nuget\packages\Newtonsoft.Json\9.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.json.dll->Click Add button.
Rebuild your Runtime Component project and run. This error should be gone.
Solution 3:
I had the same issue too, to solve this, check in References of your project if the version of Newtonsoft.Json was updated (probablly don´t), then remove it and check in your either Web.config or App.config wheter the element dependentAssembly was updated as follows:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
After that, rebuild the project again (the dll will be replaced with the correct version)
Solution 4:
I am using Visual Studio 2013 Update 2. In my case, I have a web project and a Web Api project and unit test project and other class libraries in a single solution.
I've spent couple of days to solve the problem. Below is the step-by-step solution that I have found.
- Right click on Web Api project. Select "Set as StartUp Project"
- Right click on Web Api project. Go to Properties ( Alt + Enter ).
- On the Application tab on left hand side menu, select Application
- Find Target framework. Change it to 4.5.1 and save. However, it is showing error in "Error List" window. After Rebuild, there is no error.
-
Remove all
Newtonsoft.Json
packs from solution by using below query from Package Manager Console ( to get it View > Other Window > Package Manager Console ).
uninstall-package newtonsoft.json -force
-
Reinstall
Newtonsoft.Json
from Package Manager Console
install-package newtonsoft.json
- If you have latest update for Visual Studio 2013, you might not encounter with this problem. As I am using Update 2, so, while trying to install
Newtonsoft.Json
, I have encountered with the following error.
The 'Newtonsoft.Json 10.0.3' package requires NuGet client version '2.12' or above, but the current NuGet version i s '2.8.50313.46'
- To solve this problem, we need to update the Package Manager Console. Got to
Tools > Extensions and Updates... > In left pane.. select Updates > Visual Studio Gallery.
Update the NuGet Package Manager Extension. Follow the steps that are coming afterwards.
Visual Studio will take a restart after that.
Execute step 6 again.
After Installation packages.config will be added with this below line
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net451" />
After installation web.config will be added with this below lines
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
It will execute successfully, if there is no other error.
Solution 5:
I had a similar problem with a new ASP.NET Core application a while ago. Turns out one of the referenced libraries used a version of Newtonsoft.Json that was lower than 9.0.0.0. So I upgraded the version for that library and the problem was solved. Not sure if you'll be able to do the same here