I'm working on a project which can have optional external DLL dependencies (I can not access the code of those dependencies). I moved all optional dependency code to its own class, the class is only instantiated when the DLLs are present, so I do not get any issues on runtime.
However, I want to use reflection with Assembly.GetTypes() for some other stuff, but since this tries to load said classes, I get the following exception:
System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
If the optional dependencies are loaded, I do not get such an error, since the classes can get loaded.
The related code:
foreach (var pl in R.Plugins.GetPlugins())
{
//pl has the optional dependencies
var assembly = pl.GetType().Assembly;
var types = pl.GetTypes(); //here is the exception
}
How can I use GetTypes() without loading that specific class that depends on optional dependencies?
Aucun commentaire:
Enregistrer un commentaire