问题
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
回答1:
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
回答2:
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>
来源:https://stackoverflow.com/questions/49905735/two-different-versions-of-newtonsoft-json-dll-needed-in-asp-net-mvc