Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0 issue using Google.Apis.*

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)

Doing my head in trying to find this reference. I am running a .NET Framework v4.5 project, and then importing the DLL into an aspx page.

The DLL contains a class used to connect to the Google APIs - specifically for the Google Calendar.

I've tried removing all the NuGet references and re-installing. I've ensured they are all updated to the latest stable version. The Newton.JSON library is specifically set to v13.0.1.

My packages.config file is as follows:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Google.Apis" version="1.51.0" targetFramework="net45" />
  <package id="Google.Apis.Auth" version="1.51.0" targetFramework="net45" />
  <package id="Google.Apis.Calendar.v3" version="1.51.0.2312" targetFramework="net45" />
  <package id="Google.Apis.Core" version="1.51.0" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="13.0.1" targetFramework="net45" />
  <package id="System.Net.Http" version="4.0.0" targetFramework="net45" />
</packages>

I've seen others suggesting updating the web.config file in the following folder: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config I have no idea why though. There are no references to the Newton.JSON library in there.

Where to next?

EDIT: I have resolved this as recommended below by editing the web.config of the website to point old references to the new one, however I now receive the following error:

Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

like image 683
Sami.C Avatar asked Oct 15 '25 14:10

Sami.C


1 Answers

This is usually bequase one of the other packages references Newton.JSON version 12.0.0.0 directly.(In this case probably the google apis packages)
As you add 13.0.1 to you project the other packages cant find the reference.
You can add the following bit to the config:

<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-13.0.0.0" newVersion="13.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
    <loadFromRemoteSources enabled="true" />
  </runtime>

What this does is, when you code or one of the packages references a version of Newtonsoft.Json between version 0 and 13 it will now reference version 13

like image 152
Connor Stoop Avatar answered Oct 17 '25 05:10

Connor Stoop