This project has moved and is read-only. For the latest updates, please go here.

DirectoryCatalog always load dll from BaseDirectory

Jan 22, 2010 at 11:59 AM
Edited Jan 22, 2010 at 12:01 PM



I have an application in bin folder, and plugins used by that application placed in bin\plugins folder.

I'm using DirectoryCatalog to load plugins from bin\plugins folder.


The problem is when I place some of requested plugin dlls in bin folder, even if I give the "bin\plugins" path to DirectoryCatalog, plugins from bin folder are loaded.


As I see, the problem is at line Assembly.Load(assemblyName) in method LoadAssembly in AssemblyCatalog class which always first looks at BaseDirectory of app domain, bin folder in this case.

The one solution to my problem would be using Assembly.LoadFrom instead of Assembly.Load.


Does anyone have some other solution or recommendation with or without source modifications, because this makes me a lot of trouble?


Thank you in advance,



Jan 26, 2010 at 5:49 PM

The reason that they are being loaded from the bin folder is as you pointed out the call to Assembly.Load in which the CLR will try to load via the probing path and it will look at the directory where the application was launched from before it will a sub-directory. 

I would suggest that you not try to use Assembly.LoadFrom because you will very likely end up with unexpected results because it loads the assembly in a different load context. 

My question for you would be why do you have the same assemblies in both the bin and bin\plugins directory? It is usually not a good idea to have the same assembly in multiple directories in the probing path.

Jan 27, 2010 at 12:55 PM

Thanks for reply.

The reason why I had the same dll in both paths is "people nature". :)
As you may know, if you tell the people to do one thing, and not to do the other, they will probably do the other one, so I must to be sure to exculde the influence of "people nature" to my application.

Is there any way to make application to not look into the base directory for plugins and only look into folder I set to DirectoryCatalog?





Jan 27, 2010 at 5:49 PM

There isn't any easy way that I know of to force the application to not look into the base directory because the order is baked into the CLR loader. The same thing would happen if one of the assemblies is registered in the GAC it would be loaded from there instead of from the directory.