Dependency version clashes are common when working with Sitecore, or any other large 3rd party API for that matter.
The following post describes how you can include multiple versions of the same assembly in your application, e.g. a Sitecore website.
For an in-depth reference, see the official Microsoft documentation on the
codeBase configuration element and the related assembly binding configuration section.
Code & Example
One of the more common clashes I’ve run into when working with Sitecore is the popular
Newtonsoft.Json framework — there are simply a ton of web related NuGet-packages which depend on it, because it’s that good!
The code shown below uses the
codeBase configuration element to specify the location of multiple versions of
Newtonsoft.Json included in our app.
In our case the additional configuration is added to the
Web.config-file, and the additional assembly has been added to a subfolder of the website’s
<configuration> [...] <runtime> [...] <assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1"> [...] <dependentassembly> <!-- Sitecore default config --> <assemblyidentity name="Newtonsoft.Json" publickeytoken="30ad4fe6b2a6aeed" /> <bindingredirect oldversion="0.0.0.0-126.96.36.199" newversion="188.8.131.52" /> <!-- Additional config pointing out the location of the various versions included in our solution --> <codebase version="184.108.40.206" href="bin\Newtonsoft.Json.dll" /> <codebase version="220.127.116.11" href="bin\Newtonsoft v7.0\Newtonsoft.Json.dll" /> </dependentassembly> </assemblybinding> </runtime> </configuration>