简体   繁体   中英

Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies?

when I am debugging i faced an exception at below point.

var connection = new HubConnection("http://localhost:8080/");

Exception:
Could not load file or assembly 'Newtonsoft.Json, Version=6.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 had created a folder I dumped my serverHub.exe(console App) and a client module which is of winforms. In the client side when I tried calling the above step mentioned I got the exception.

First I had installed Newtonsoft.Json of version=6.0.0.0, later I updated it to version=9.0.1. Now I copied the dll's (Microsoft.Asp.Net.Client.dll, Newtonsoft.Json.dll along with other dll's required) required into the common folder I had created. This is when i started facing the exception.

Now the references (Newtonsoft.Json.dll, Microsoft.Asp.Net.Client.dll) in my project are referring to the folder I had newly created where I dumped the copied dlls from "packages" location.

Again I removed these references and downloaded the Nuget packages from package manager(Microsoft.Asp.Net.Client.dll-version:2.2.1 & Newtonsoft.Json.dll-9.0.1). and the references are now referred from package location. Now I tried building my application and now it is working fine.

App.config(Client's):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <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>

    </assemblyBinding>
  </runtime>
</configuration>

App.config(server):

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
  </dependentAssembly>
  <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>
</assemblyBinding>

If I start referring to a different location where I will copy all the dll's which are installed rather than of a default "Packages" location under solution directory I am facing the above exception.Can't we make the dll's to refer from a different location rather than default "packages" location? If yes please help where I am doing wrong.

Can any one please help me.

I would try to change binding redirect to <bindingRedirect oldVersion="0.0.0.0-9.0.1.0" newVersion="9.0.1.0" />

If this does not help try to check by this tool the new location where you run your executables in order to see what actually is missed: https://stackoverflow.com/a/44251000/2819746

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM