2

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'

Sami.C
  • 561
  • 1
  • 11
  • 24
  • how did you add these packages? By checking the github page it looks like the google .net client library should still support .net45. No chance you want to upgrade to something from this decade? – Linda Lawton - DaImTo Jun 01 '21 at 07:14
  • the `web.config` of your .net project should be updated and not the one in C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config – Akshay G Jun 01 '21 at 07:22
  • I’ve essentially written my own wrapper class which consumes the google apis with a nuget install. I then import my library into the aspx page. – Sami.C Jun 01 '21 at 10:01

3 Answers3

4

Look into the .csproj file it should also been updated v13

sample

 <ItemGroup>
    <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
    </Reference>
    <Reference Include="System.Net.Http" />
  </ItemGroup>

and make sure the dependent Assembly in web config also has been updated

Sample:

  <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
  </dependentAssembly>
  • 1
    This helped me. I have two projects in one solution ... one was running 12 and the other 13. Comparing the .config files made this apparent. – Rodney Ellis Feb 04 '22 at 09:55
  • This answer helped me to fix the issue for version 13.0.0.1. The issue is still open on githuub but above workaround can fix the compilation error. Thanks. – sanpat Aug 10 '23 at 23:02
4

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

Connor Stoop
  • 1,574
  • 1
  • 12
  • 26
  • 1
    Which config file are you referring to? The app.config inside my class library being imported or something attached to the aspx page? – Sami.C Jun 01 '21 at 08:13
  • The app config or web config of the executing assembly.So the startup project – Connor Stoop Jun 01 '21 at 08:15
  • The dll is being called by an aspx page that is running inside IIS. I could try adding this to the web.config of the website, I’ll try and report back if you think that’ll work. – Sami.C Jun 01 '21 at 09:39
  • I just tried this and it worked, however I'm now presented with a new one: Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' Any ideas on this? Neither "System.Reflection.IntrospectionExtensions or mscorlib are showing up as references in my project – Sami.C Jun 01 '21 at 10:10
  • you cloud check : https://stackoverflow.com/questions/7932994/could-not-load-type-system-reflection-introspectionextensions-from-assembly-m – Connor Stoop Jun 01 '21 at 11:02
  • Yeah I had a look at that. I’m already using 4.5 though – Sami.C Jun 01 '21 at 11:15
  • Why redirecting to 13.0.0.0, while the package version is 13.0.1? How the loader will know the 13.0.1 is ok and the right one? – Guillaume Pascal Feb 23 '23 at 10:26
  • 1
    @GuillaumePascal As far as I know (Ind I am not sure)13.0.0.0 means every version in version 13 – Connor Stoop Feb 23 '23 at 14:23
1

I had this same problem and found it important to note something else. Connor's answer was correct but my users still had this issue. My app is a WPF application whereas even though I had this change in my app.config they did not have it in theirs. It took a couple hours to track down while it was failing for them.

pccoder
  • 31
  • 7