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

后端 未结 17 2388
渐次进展
渐次进展 2020-12-03 00:43

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 Javascrip

17条回答
  •  隐瞒了意图╮
    2020-12-03 01:34

    I had a very similar problem. I was trying to use Newtonsoft.Json.dll in a .NET DLL, in the same way that I am successfully using it in .NET EXEs on my computer. I used NuGet in my Visual Studio 2017 to add Newtonsoft.Json to MyDll.dll. MyExecutable.exe references MyDll.dll. Calling a Newtonsoft.Json method from code within MyDll.dll raised "System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.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)".

    I ran Microsoft's fuslogvw.exe https://docs.microsoft.com/en-us/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-viewer to check what was being loaded and found the following:

    LOG: Post-policy reference: Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
    LOG: GAC Lookup was unsuccessful.
    LOG: Attempting download of new URL file:///C:/MyExecutable/bin/Debug/Newtonsoft.Json.DLL.
    LOG: Assembly download was successful. Attempting setup of file: C:\MyExecutable\bin\Debug\Newtonsoft.Json.dll
    LOG: Entering run-from-source setup phase.
    LOG: Assembly Name is: Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
    WRN: Comparing the assembly name resulted in the mismatch: Major Version
    ERR: The assembly reference did not match the assembly definition found.
    ERR: Run-from-source setup phase failed with hr = 0x80131040.
    ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
    

    MyExecutable.exe had no references or calls to Newtonsoft.Json, yet I found a 6.0.0.0 Newtonsoft.Json.dll in bin\Debug directories of copies of my MyExecutable source tree from before I added any Newtonsoft.Json references to any of my code. I do not know why the 6.0.0.0 Newtonsoft.Json.dll was there. Perhaps it was referenced by another DLL referenced by MyExecutable. I avoided the FileLoadException by using NuGet to add a reference to 12.0.0.0 Newtonsoft.Json to MyExecutable.

    I expected that binding redirect in MyExecutable’s App.config as illustrated below would be an alternative to MyExecutable’s referencing Newtonsoft.Json, but it did not work. …

提交回复
热议问题