I have a program that should use a large number of plugins.
Each plugin must support a very simple interface, this interface is defined in a DLL (IBaseComponent for simplicity of matter).
Each plugin will be located in a specific directory (AppDirectory \ plugin \ plugin-type). Each plugin can have any name for the plugin dll (AppDirectory \ plugin \ plugin-type \ plugin-name.dll).
Therefore, I need to check every subdirectory of the plugin, find each plugin with a class that supports the IBaseComponent interface, create an instance of the class and call some functions on the plug-in.
ok, everything is fine and dandy, none of this is particularly hard. The problem is that I seem to run into some weird issues.
Each plugin should have the Base.dll file in separate plugin folders (and not just in the program that will load the plugin), and it also seems that I get a lot of errors and warnings about dynamic loading of dlls that have dlls that also need to be loaded.
I use:
pluginModule = System.Reflection.Assembly.ReflectionOnlyLoadFrom(PathToAssembly);
to grab the dll plugin and use:
types = moduleAssembly.GetTypes();
to capture the types contained in the dll. I repeat the types and check if the separate interface type is IBaseComponent (meaning that it is a valid load class):
if (type.GetInterface("FrameworkNameSpace.IBaseComponent") != null)
Later, to actually create an instance of the class from the dll, I use:
pluginModule = System.Reflection.Assembly.LoadFrom(PathToAssembly);
and then use:
types = component.GetTypes();
To get the types inside the module, select and load a class that supports the interface, as described above.
The problem is that I am using:
types = component.GetTypes();
When actually trying to load a class, instead of just looking at it. (Hence my various use of LoadFrom and ReflectionOnlyLoad)
The exception that I get when calling GetTypes (in the second plug-in, but never the first!):
{"Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information."}
With the LoaderExceptions property:
{"The specified module could not be found. (Exception from HRESULT: 0x8007007E)":null}
I am not sure why this is happening. The DLL is located in the plugin folder, and the DLL containing the IBaseComponent interface is also located in each plugin directory. Am I going about it wrong?
Also, do I need to save a copy of the DLL containing the IBaseComponent in each subdirectory of the plug-in, as well as the one used by the program itself, or am I doing something wrong that will allow me to remove this requirement?
I am aware of the MEF I wanted to use, but unfortunately, because I need to support this on .net 2.0. I can not use MEF.