I have a .NET application which I wish to search other paths for dependent DLLs besides the standard GAC, current directory, PATH areas. Is it possible to tell the app to do this?
E.g.
Tell the Application to look in "[Executable Path]\Dependent DLLs".
If the DLL is listed in the Windows registry in the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\KnownDLLs key, Windows searches for the DLL in the following locations in order: The %SystemRoot%\SYSTEM32 directory. The .exe file directory. The current directory.
You can add a private assembly search path by using the <probing>
element in your .config file.
An alternative approach to setting probing in you config (if you require more flexibility) - is that you can add your own handler to search other locations and load them yourself.
In the main method that starts your app
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainAssemblyResolve;
add a handler with your own method to take the name and search other locations -
private static Assembly CurrentDomainAssemblyResolve(object setnder, ResolveEventArgs args)
{
return LoadEmbeddedAssembly(args.Name);
}
I use this method to embed DLLs as resources so I can have a single executable to distribute, but you can load them from a directory just as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With