Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies

Kishor Bikram Oli picture Kishor Bikram Oli · Jul 30, 2016 · Viewed 137.6k times · Source

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.

enter image description here

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:

enter image description here

I tried removing all the Newtonsoft json and re-installing it but no luck.

Answer

Elvis Xia - MSFT picture Elvis Xia - MSFT · Aug 2, 2016

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:

  1. 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.

  2. Rebuild your Runtime Component project and run. This error should be gone.