How can I add a path(s) to the DLL search order
Asked Answered
S

2

6

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".

Shading answered 26/7, 2011 at 21:6 Comment(2)
you don't give enough information... does the app load the dependent DLLs dynamically - via Assembly.LoadFrom ?Comedown
It's loading Workflows using a XamlXmlReader and ActivityXamlServices.Load. The dependent DLLs will be dynamic based on the loaded XAML file.Shading
S
6

You can add a private assembly search path by using the <probing> element in your .config file.

Shih answered 26/7, 2011 at 21:14 Comment(0)
E
2

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.

Enteron answered 26/7, 2011 at 21:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.