You need to use a dependentAssembly with bindingRedirect but also you need put dlls in different folder or save with a different name. With this done, you need to put the following in your app.config:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="here token dll"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
<bindingRedirect oldVersion="1.0.0.1-2.0.0.0" newVersion="2.0.0.0" />
<codeBase version="1.0.0.0" href="https://stackoverflow.com/questions/42715564/folder\namedll.dll" />
<codeBase version="2.0.0.0" href="https://stackoverflow.com/questions/42715564/folder\namedll.dll" />
</dependentAssembly>
</assemblyBinding>
With this code should compile and run, but sometimes VS deletes or overwrite the code in the app.config when compiles it. You need to check it in config file of compilation folder. If this succeeds, you can edit the .csproj. For this you must do:
1- Unload the project affected
2- Right click on project
3- Click Edit project
4- Find the<AutoGenerateBindingRedirects>property and set it to False
5- Save changes and reload project
This works for me. In my project, I’m using two versions of Automapper.
Finally, another solution is to use the AppDomain.CurrentDomain.AssemblyResolve build event and load the specific dll.
For that, you need catch the event:
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
public static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
//debug and check the name
if (args.Name == "MyDllName")
return Assembly.LoadFrom("c:\\pathdll\midllv1.dll")
else if(args.Name ="MyDllName2")
return Assembly.LoadFrom("c:\\pathdll\midllv2.dll");
else
return Assembly.LoadFrom("");
}