Im trying to run two versions of
Newtonsoft.Json.dll within my site as im using two different plug-ins requiring different versions of
Newtonsoft.Json.dll version 6 and version 9.
Came across this article Two different versions of Newtonsoft.Json.dll needed in ASP.NET MVC which is the same problem (but for Win forms if that makes any difference). So my web.config file looks like
<dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <codeBase version="22.214.171.124" href="Newtonsoft.Json.dll" /> <codeBase version="126.96.36.199" href="dlls\188.8.131.52\Newtonsoft.Json.dll" /> </dependentAssembly>
I know version 6 of NSJson works as everything was working until i added the second plugin. If i look at the dll's properties, under the Details tab i see File and Product version as 184.108.40.20613.
I then created a folder under the bin directory called dlls\220.127.116.11\Placed dll in here. If the version is listed as
version="18.104.22.168" i get the error
Could not load file or assembly 'Newtonsoft.Json, Version=22.214.171.124, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
If i change the version to
version="126.96.36.199" then i get
Could not load file or assembly 'Newtonsoft.Json, Version=188.8.131.52, 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)
Which "seems" to imply that im closer to the solution rather than setting the version as 184.108.40.206 but i dont know how to see what manifest definitions its looking for or what it should be set to? Of course i could be totally wrong and wonder how i go about resolving this issue?
Unfortunately what you are trying to do is not possible with the CLR (technically it is with extern aliasing, but no!), you can only have one version of an assembly loaded within an
AppDomain (here your app).
This is where "Binding Redirects" come in, you'll need your config to tell the runtime that whenever it tries to load
Newtonsoft.Json, Version=220.127.116.11, ... to use version
18.104.22.168 or whatever version.
The binding redirect config looks like this:
<dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-22.214.171.124" newVersion="126.96.36.199"/> </dependentAssembly>
You have to use assembly binding redirect. Your code will be like this:
<dependentAssembly> <assemblyIdentity name="C" publicKeyToken="32ab4ba45e0a69a1" culture="en-us" /> <bindingRedirect oldVersion="188.8.131.52" newVersion="184.108.40.206" /> </dependentAssembly>
More information you can find here.
User contributions licensed under CC BY-SA 3.0