Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two different versions of Newtonsoft.Json.dll needed in ASP.NET MVC

I have developed a MVC application that has dependency on Connectwise SDK that uses Newtonsoft.Json.dll v6.0.0.0 and Dropbox SDK that uses Newtonsoft.Json.dll v7.0.0.0.

I need to ensure that my project uses the appropriate dll when needed. After researching, I tried the following: - Placed the 2 dlls under sub-folders /dlls/6.0.0.0/ and /dlls/7.0.0.0 resp. - Referenced version 6.0.0.0 dll in project References - Added to web.config

<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"></bindingredirect>          
        </dependentAssembly>
       <dependentAssembly>
          <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"
            culture="neutral" />
          <bindingredirect oldVersion="7.0.0.0-7.1.0.0" newVersion="7.0.0.0"></bindingredirect>
          <codeBase version="7.0.0.0" href="dlls/7.0.0.0/Newtonsoft.Json.dll" />
        </dependentAssembly>
      </assemblyBinding>     

Could not load file or assembly 'Newtonsoft.Json, Version=7.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)

Is my href incorrect ?? dlls folder is in the same level as Content folder in MVC project

Thanks, Gagan

like image 953
Gags Avatar asked Apr 18 '18 17:04

Gags


2 Answers

Try this assemblyBinding block instead, note the subtle differences...

I've removed the bindingredirect node because you don't need it!

I've changed the slash to backslash in your href attrib

And of course you're going to need 2 codeBase nodes

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
   <dependentAssembly>
      <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"
        culture="neutral" />
      <!-- You don't need binding redirect, because you're not targeting old version to new,
      ---- instead you're catering to 2 different versions.
        <bindingredirect oldVersion="7.0.0.0-7.1.0.0" newVersion="7.0.0.0"></bindingredirect>
      -->
      <codeBase version="6.0.0.0" href="bin\json6\Newtonsoft.Json.dll" />
      <codeBase version="7.0.0.0" href="dlls\7.0.0.0\Newtonsoft.Json.dll" />
    </dependentAssembly>
  </assemblyBinding>
like image 124
Sawrub Avatar answered Sep 30 '22 19:09

Sawrub


I had also hit the same issue. I solved using codebase methods mentioned in this link. https://devnet.kentico.com/articles/referencing-multiple-versions-of-the-same-assembly-in-a-single-application

like image 38
Shashwat Gupta Avatar answered Sep 30 '22 19:09

Shashwat Gupta