I am working on a framework that allows dynamic loading of plugins at runtime without directly referencing their DLLs. The plugins are instantiated dynamically during runtime. However, I’m facing an issue with dependencies between plugins. If one plugin depends on another, and they belong to different assemblies, I encounter problems when trying to retrieve constructor parameters via reflection.
Specifically, when retrieving constructor parameters, I may encounter types that are referenced by the plugin but are not recognized by the framework. This leads to exceptions such as “File not found” when attempting to load these types. Even if I successfully retrieve all constructor parameters for a plugin, using Activator.CreateInstance can still throw exceptions for the same reason.
I have tried bundling plugins and their dependent DLLs together, but this approach results in the references being updated to internal references within the merged DLL. Consequently, types referenced across different assemblies are no longer recognized as the same.
How can I resolve this issue?
The problem I’m handling is like this:
// A.dll
public class PluiginA(IPluginB pluginB) : PluginController
{
...
}
// B.dll
public class PluiginB() : PluginController
{
...
}
public class Program
{
public static void Main() {
var assemblyA = Assembly.LoadFrom("pathToA.dll");
var classNameA = assemblyA.GetExportedTypes().FirstOrDefault(
x => x.BaseType == typeof(PluginController)));
var constructorA = classNameA.GetConstructors()[0];
// This line leads to System.IO.FileNotFoundException because PluginA's constructor parameters references a type from B.dll, and the framework cannot resolve it.
var parameterInfoA = constructorA.GetParameters();
}
}