DLL Hell with COM modules
Posted: Mon May 23, 2022 12:52 pm
Hello all,
in one of my (VO) applications I'm using several COM modules, and with a new version of a used library I had the problem that I had a classic case of DLL hell: two libraries I used had dependencies on different versions of the System.Threading.Tasks.Extensions.dll library.
After a few hours of searching I found a very interesting solution: put them in different subdirectories of the application directory and then use the AssemblyResolve event to redirect the load to the correct path:
You have to register as follows:
That way you can also change the loading path for other runtime DLLs.
Wolfgang
in one of my (VO) applications I'm using several COM modules, and with a new version of a used library I had the problem that I had a classic case of DLL hell: two libraries I used had dependencies on different versions of the System.Threading.Tasks.Extensions.dll library.
After a few hours of searching I found a very interesting solution: put them in different subdirectories of the application directory and then use the AssemblyResolve event to redirect the load to the correct path:
Code: Select all
protected method AssemblyResolve( oSender as object, oArgs as ResolveEventArgs ) as Assembly
local oAssembly as Assembly
local cFileName as string
local cAsmFile as string
if oArgs:Name:Contains( ".resources")
return null
endif
// check for assemblies already loaded
oAssembly := AppDomain.CurrentDomain.GetAssemblies():FirstOrDefault( { a => a:FullName == oArgs.Name } )
if oAssembly != null
return oAssembly
endif
cFileName := oArgs:Name:Split( ',') [1] + ".dll":ToLower()
cAsmFile := Path.Combine ( ".","AlpiComLib", cFileName )
try
return System.Reflection.Assembly.LoadFrom( cAsmFile )
catch // oEx as Exception
end try
return null
Code: Select all
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve
Wolfgang