I developed a DLL in Managed C++ which loads some plugins (implemented in any .NET language) at runtime using System.Reflection.Assembly.LoadFile. The interface which is implemented by all plugins is implemented in C#. It's used by the Managed C++ code like this:
#using <IMyPluginInterface.dll> // Make the 'IMyPluginInterface' type available
ref class PluginManager {
List<IMyPluginInterface ^> ^m_plugins;
// Load all plugins in a well-known directory.
void load() {
for ( string dllFile in Directory.GetFiles( .., "*.dll" ) ) {
// Lookup the type of the plugin object using Reflection
Type pluginType = ...;
// Finally, instantiate the plugin and add it to our list.
m_plugins.Add( (IMyPluginInterface ^)Activator.CreateInstance( pluginType ) );
}
}
}
Loading the plugins works well; the problem I'm facing is that at runtime, the IMyPlugnInterface.dll
file might not be in the same directory as the Managed C++ DLL. This means that the 'IMyPluginInterface' type is not available at runtime, and an exception is thrown.
I previously asked whether it was maybe possible to influence the lookup path used when resolving DLLs referenced via the #using
statement. Unfortunately, this didn't yield any result.
Is there maybe a different approach to this? Can types which are referenced via #using
be compiled into the Managed C++ DLL? Maybe anybody else has an entirely different solution?