.netvisual-studioassembly-resolution

Referencing Assemblies in a .Net Application


In my application, I would like to load Assemblies that reside on a network share (The application itself is on that share, too) without having to add them to the project's output path. What I'd like to have is an output directory that contains next to nothing but the application.

Merely adding the target directory to my project's reference path's won't work.

I tried setting the probing directory in the App.Config, but that didn't work (even tested it on my local diks instead of the network share)

Thanks in advance for any hints!

EDIT : Seems the way this is going leads through reflection. Isn't there a more elegant way using Dependency Injection containers like NInject?


Solution

  • Unfortunately you can't add an arbitrary directory to your probing path: only a subdirectory within your application.

    However, it's possible to provide full paths to assemblies using the <codeBase> element within an <assemblyBinding>. There's an example on the MSDN page for <assemblyBinding>. The downside is that you'll need to explicitly list paths for all the assemblies your application references.

    Another option is to load assemblies at run time through Assembly.LoadFrom and invoke methods through reflection. If you go down this route, you must read Suzanne Cook's blog. If you read nothing else, read Choosing a Binding Context.