Using multiple versions of a DLL in ASP.NET and .NET apps


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 bin-folder.

    <assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1">  
        <!-- Sitecore default config -->
        <assemblyidentity name="Newtonsoft.Json" publickeytoken="30ad4fe6b2a6aeed" />
        <bindingredirect oldversion="" newversion="" />
        <!-- Additional config pointing out the location of 
             the various versions included in our solution -->
        <codebase version="" href="bin\Newtonsoft.Json.dll" />
        <codebase version="" href="bin\Newtonsoft v7.0\Newtonsoft.Json.dll" />

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s