How to load same assembly of different version in one application?


I have Windows forms application in C#. I am in need to make use of the below dll.


The problem is that I need to refer two different versions of this same assembly.

I tried keeping the dll in two different locations & tried to add but not allowing.

Following the below link, I tried to load two version of a assembly on runtime, but somehow not sure how do I do that.

This is how my app.config looks like:-

<assemblyBinding  xmlns="urn:schemas-microsoft-com:asm.v1">
    <assemblyIdentity name="Interop.SHDocVw.dll" publicKeyToken="db7cfd3acb5ad44e" />
    <codeBase version="1.1.0" href="...\watin-core\Interop.SHDocVw.dll"/>

    <assemblyIdentity name="Interop.SHDocVw.dll" publicKeyToken="632609b4d040f6b4" />
    <codeBase version="1.3.0" href="...\winforms\Interop.SHDocVw.dll"/>

Currently the exception it is throwing:-

System.IO.FileLoadException: Could not load file or assembly 'Interop.SHDocVw, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
 File name: 'Interop.SHDocVw, Version=, Culture=neutral, 
 at myApp.AppUI.InitializeComponent()

How do I address this?

asked on Stack Overflow Feb 5, 2018 by Kgn-web • edited Dec 21, 2018 by halfer

2 Answers


as in :

1) Edit your csproj file (right click on project in solution explorer , then unload project then, modify csproj file)

2) in this csproj file, add in ItemGroup containing Reference tags: (here an example with Office Interop 15 and 16)

<Reference Include="Microsoft.Office.Interop.Excel, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
  <HintPath>C:\Program Files (x86)\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA\Office15\Microsoft.Office.Interop.Excel.dll</HintPath>


<Reference Include="Microsoft.Office.Interop.Excel, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
  <HintPath>C:\Program Files (x86)\Microsoft Office\root\Office16\DCF\Microsoft.Office.Interop.Excel.dll</HintPath>

as you can see, I've added Aliases : Test1 and Test2

3)Then, reload project and in your .NET Code , add at the very first line of your code (before any "using"):

extern alias Test1;
extern alias Test2;

then in your code you can use the same assembly with 2 distinct versions:

Test1.Microsoft.Office.Interop.Excel.Application app1;
Test2.Microsoft.Office.Interop.Excel.Application app2;

screenshot of the c# code window

.csproj file

Update 2019 dec 18 after comment from user203687 (I have downloaded your sample code and made it work with the app.config add-on below) : (adding a codebase reference solved the issue)

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <assemblyIdentity name="SampleLib" publicKeyToken="2901d9e7607fc6eb" />
    <codeBase version="" href="YourFullPathTo\Lib-v1\SampleLib.dll" />
    <codeBase version="" href="YourFullPathTo\Lib-v2\SampleLib.dll" />
answered on Stack Overflow Feb 5, 2018 by Xavave • edited Dec 18, 2019 by Xavave

I think when you say - "you can run two different versions of same assembly side by side" means that you can have two versions of assembly allowed to be loaded into same app domain.

This means in your application :

Assembly1 (lets say you name your cs proj as Assembly1) can refer version 1.1 of Interop.SHDocVw.dll

And Assembly2 ((lets say you name your cs proj as Assembly2) can refer version 1.3 of Interop.SHDocVw.dll.

Your final o/p directory will have Assembly1.dll, Assembly2.dll and both the versions of Interop.SHDocVw.dll.

answered on Stack Overflow Feb 5, 2018 by rahulaga_dev

User contributions licensed under CC BY-SA 3.0