Greetings,
I have a C# application that uses Reflection to scan through a directory, ./plugins/, for assemblies that have been assigned the PluginAttribute and loads them.
This part works beautifully. I can create new plugins, copy them into the ./plugins/ directory, the application finds them and loads them. Cool. For basic ./plugins/ this all works great.
The problem that I am running into is when plugins are a bit more complicated and have references to other projects. The referenced project gets compiled and the referenced DLL accompanies the plugin's DLL in the ./plugins/ folder.
.NET doesn't like this. When the plugin is instantiated a FileNotFound exception is thrown. If I move the DLL referenced by the plugin from ./plugins/ to ./ then all works great.
I don't want to do this though. I want the referenced DLL to stay with the plugin. :) How can I leave it the referenced DLL in ./plugins/ and inform .NET to look in that directory for the assembly rather than only looking ./?
I have tried adding the ./plugins/ directory to the Reference Paths tab in the project Properties for each of the projects involved to no avail.
I found an article from somebody else who had this problem. They worked around the issue by wiring up an AppDomain.CurrentDomain.AssemblyResolve event handler to load an assembly via Reflection then dismantling the event handler but that seems like an ugly workaround.
Is there a better way?
Cheers!
Andy P