Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

In package manager console execute: Update-Package –reinstall Newtonsoft.Json.

UPDATE

I originally posted this as a comment but as @OwenBlacker suggested I'll just put it here:

If you still get an error after doing this, then what worked for me eventually is that I deleted Json.Net's <dependentAssembly> section from my .config file. Reinstall brings it back if it's not there and apparently you need to delete it. Until there will be a normal solution in the package itself, I'm afraid this manual step is a must.

Note: Please read the comments below before doing this.

As per René's comment below BE AWARE that the command posted in the answer will reinstall the package in every project in your solution. So if you use the Newtonsoft.Json package in several projects and maybe use different versions, just executing the above command might have unwanted consequences.


To everyone having problems with Newtonsoft.Json v4.5 version try using this in web.config or app.config:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
           <assemblyIdentity name="Newtonsoft.Json"
               publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
           <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
       </dependentAssembly>
    </assemblyBinding>
</runtime>

IMPORTANT: Check that the configuration tag of your config file has no namespace attribute (as suggested in https://stackoverflow.com/a/12011221/150370). Otherwise, assemblyBinding tags will be ignored.


The key point is referencing right version in your config file.

Steps;

1- look at what is the version of your Newtonsoft.Json.dll in the project reference property what ever the version in your package folder (For example mine is 7.0.1 and the reference Version is 7.0.0.0)

2- look at what the project expect from you in the exception (mine is 6.0.0.0)

3- Add dependent assembly to your config file as it should be..

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json"  publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="7.0.0.0"/>
  </dependentAssembly>

I had no luck with any of the solutions presented here (uninstalling, reinstalling, deleting references, creating bindingRedirects etc.) I had to go back to an old version of Newtonsoft. Version 5.0.6 had been working before, so I tried that one. I had to enter these two commands in the Package Console:

uninstall-package newtonsoft.json -force

install-package newtonsoft.json -version "5.0.6"

The -force option in the first command is required to force the uninstall. Dependencies with other assemblies prevent the uninstall without it.


I fixed the problem adding this binding redirect to my .config file:

<runtime>
    . . . 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"
                culture="neutral" />
            <bindingRedirect oldVersion="4.5.0.0" newVersion="6.0.0.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

The error message complains about not finding version 4.5.0.0, the current version of Newtonsoft.Json is 6.0.0.0 so the redirect should go from 4.5 to 6.0, not viceversa