Search code examples
c#asp.netasp.net-mvckendo-asp.net-mvc

Impossible to load two versions of the same libary in ASP.NET MVC


We're using Telerik kendo library which allow us to use advanced UI widgets in our ASP.NET MVC project. Last week I was encouraged to upgrade the library, but we thought than we can have the same library linked twice trying to upgrade the library in some views and do the migration along the time.

But my attempt failed.

I registered two versions of the Telerik kendo library which assembly and library name is Kendo.Mvc in the csproj, to do this I renamed both libraries and I referenced in the project using the following code block. Furthermore I create aliases to reference each library version using 'extern aliases':

<Reference Include="Kendo.Mvc.2020, Version=2020.3.1021.545, Culture=neutral, PublicKeyToken=121FAE78165BA3D4">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\vendor\Kendo.Mvc.2020.dll</HintPath>
  <Aliases>Kendo_2020</Aliases>
  <Private>True</Private>
</Reference>
<Reference Include="Kendo.Mvc.2016, Version=2016.3.1118.545, Culture=neutral, PublicKeyToken=29AC1A93EC063D92">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\vendor\Kendo.Mvc.2016.dll</HintPath>
  <Aliases>Kendo_2016</Aliases>
  <Private>True</Private>
</Reference>

After that I change the codebase in the web.config to show where is the appropriate library version:

  <dependentAssembly>
    <assemblyIdentity name="Kendo.Mvc" publicKeyToken="29AC1A93EC063D92" culture="neutral" />   
    <bindingRedirect oldVersion="0.0.0.0-2016.3.1118.545" newVersion="2016.3.1118.545" />
    <codeBase version="2016.3.1118.545" href="Kendo.Mvc.2016.dll"/>
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Kendo.Mvc" publicKeyToken="121FAE78165BA3D4" culture="neutral" />
    <bindingRedirect oldVersion="2016.3.1118.546-2020.3.1021.545" newVersion="2020.3.1021.545" />
    <codeBase version="2020.3.1021.545" href="Kendo.Mvc.2020.dll"/>
  </dependentAssembly>

Then I tried to use each version of the library using the extern links, like that:

extern alias Kendo_2016;
using Kendo_2016.Kendo.Mvc.Extensions;
using Kendo_2016.Kendo.Mvc.UI;
...

The bin folder has the two libraries:

bin folder

But when I launch the project, It shows an error that shows that it's impossible to find a library:

error

Why it can't load the library if it's in the right place?

Thank you!


Solution

  • Finally, after some researching hours I've got the answer In this post, and it works like a charm!.

    The problem was that signed assemblies with a "Strong Name" secure it from some sort of modifications, between them, file renaming.

    I was able to use ReflexIL to rename the assembly removing "Strong Name" and voila.