Using external assemblies: The located assembly's manifest definition does not match the assembly reference
I know this question seems to be answered all over stackoverflow and the web, but my issue is different.
I am trying to understand how to not use the GAC (boss says no) when I have the following setup:
The project uses NHibernate, and Antlr3.Stringtemplate Both of which are third party assemblies. NHibernate has a reference to Antlr3.Runtime version 3.1.3.42154 Antlr3.Stringtemplate has a reference to Antlr3.Runtime version 3.3.1.7705
One will error when the other is not available.
I tried binding redirect, but this does not work because the publicKeyToken is different between the versions. It ends up looking for a 3.3.17705 with a public key token that matches the 3.1.3.42154 version.
Installing one, o开发者_如何学编程r both, in the GAC works. However, my boss won't let me install anything into the GAC.
I also tried putting both DLLs in the BIN directory, by including a Lib project with a folder for version 3.1.3.42154. I told it to copy always and so I get /bin/Lib/3.1.3.42154/Antlr.Runtime.dll Then I added a probing element to probe that directory. This did not work, and I got the same exact error.
How can you use third party assemblies that reference another third party assembly, both both reference different versions?
UPDATE:
System.Reflection.Assembly.LoadFile(@"Antlr3.Runtime.dll"); // 3.3.1
System.Reflection.Assembly.LoadFile(@"Antlr3.Runtime\Antlr3.Runtime.dll"); // 3.1.3
AppDomain.CurrentDomain.GetAssemblies() shows that the versions are loaded in the app domain, however, it still errors saying thta 3.1.3 cannot be found.
The following is whats loaded from AppDomain.CurrentDomain.GetAssemblies() right before the invocation to the code that errors. The first 2 lines are whats in GetAssemblies() the third line is what the error says is missing.
{Antlr3.Runtime, Version=3.3.1.7705, Culture=neutral, PublicKeyToken=eb42632606e9261f}
{Antlr3.Runtime, Version=3.1.3.42154, Culture=neutral, PublicKeyToken=3a9cab8f8d22bfb7}
Antlr3.Runtime, Version=3.1.3.42154, Culture=neutral, PublicKeyToken=3a9cab8f8d22bfb7
Solved the problem.
This is a specific issue with using Antlr3.StringTemplate The guy who made stringtemplate actually downloaded the source of antlr and built it with his application instead of distributing the original antlr dll. His new antlr dll has the same name, but different signature. He changes the version, and the public key token of it. So it causes very bad conflicts if you try to use the original with things such as NHibernate.
So the solution was to use ILMerge to merge his custom Antlr3 DLL into the string.template DLL to make the string.template dll dependent on nothing but itself. I merged Antlr3.Runtime.dll, Antlr3.StringTemplate.dll, and Antlr3.Runtime.Debug.dll into a single DLL Antlr3.StringTemplate.dll
This removed all DLL conflicts, and I was able to include the Antlr3.Runtime.dll that nhibernate needs. The guy who produces stringtemplate should just distribute his package this way too.
精彩评论