Microsoft Application block DLL V2 and V4.1 references
My application is referencing Microsoft Enterprise library V4.1 while one of the older DLL (external application) requires a reference to Microsoft Enterprise library V2.0. I know for sure that i can register both of these assemblies in the GAC and the application will start reading relevant DLL as required but that is not a solution for us since our security expert is not agreeing upon accepting this solution.
Is there any way using the webconfig where I can specifically specify that the Older DLL use V2.0 while the entire application uses 4.V0.
note : We're using Asp.net visual Studio C#
Help needed desperately ! Thanks
Update :
Tried the soluti开发者_如何学编程on of using privatePath probing :
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;ExtDLL"/>
</assemblyBinding>
My Web folder now has ExtDLL folder which contains V2.0.0.0 Dlls for Microsoft Enterprise library, but i still get the following exception as soon as i call the external DLL's function which is using V2.0.0.0 assembly:
...System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, 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)
Have you tried something like this? This is currently the technique that I use for supporting multiple versions of DLL in an application, whilst avoiding the GAC.
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MyLibrary" publicKeyToken="605f591b87e816bd"/>
<codeBase version="1.0.0.0" href="./v1/MyLibrary.dll"/>
<codeBase version="2.0.0.0" href="./v2/MyLibrary.dll"/>
</dependentAssembly>
</assemblyBinding>
The make sure you have:
- Your DLLs are strongly named
- the appropriate directory structure (v1/MyLibrary.dll and v2/MyLibrary.dll) is in your binary folder
- None of the DLLs that appear in these 'subfolders' should appear directly within your binary folder.
This is a simple solution - but I would reccomend that you actuall name your subfolders the same are they would be in the GAC, such as:
./MyLibrary/1.0.0.0__605f591b87e816bd/MyLibrary.dll
./MyLibrary/2.0.0.0__605f591b87e816bd/MyLibrary.dll
./MyLibrary/2.0.0.0_en_605f591b87e816bd/MyLibrary.dll (this is an example of a build that is localized, satellite assemblies would always appear like this)
I was unable to be able to load both versions of Enterprise Library using probing/privatePath or codebase configuration.
The only way I was able to get it to work was using custom resolving of assembly loads..
I placed the 2.0 assemblies in the application bin directory. Then I placed the 4.1 assemblies in a directory called EL41 under bin (bin\EL41). I then added custom event handler to try to resolve the assembly by adding
AppDomain.CurrentDomain.AssemblyResolve += newResolveEventHandler(MyResolveEventHandler);
to startup code and then creating the MyResolveEventHandler
private static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
{
string[] assemblyInfo = args.Name.Split(',');
return Assembly.LoadFrom(@"file:///C:/Documents and Settings/My Documents/Visual Studio 2008/Projects/App/bin/EL41/" + assemblyInfo[0] + ".dll");
}
This definitely will work. You could place the path in configuration to avoid hard coding the location but it still feels wrong to me. I wonder if there is a less intrusive way to do what you want.
精彩评论