I hav ea program which dynamically loads and adds elements based on all found dlls in a given directory. (in short: Assembly.LoadFrom("...xyz.dll").GetTypes().Where(t => typeof(MyBaseClass).isAssignableFrom(t).Select(t => Activator.CreateInstance(t)))
Now some of my Dlls (including multiple classes derived from MyBaseClass) require additional referenced Dlls, which are not always included (like when using an API-Dll from another program). Those are typically handled by my AppDomain.CurrentDomain.AssemblyResolve event, where I dynamically load those missing API-DLLs based on some installation paths) As a result, when using assembly.getTypes(), I get an "ReflectionTypeLoadException ex" with a subtype "FileNotFoundException" as part of the ex.LoaderExceptions.
To clarify: this exception is ok, because some API-Dlls are part of other programs; so if you run my program on another PC without these programs installed, of course the referenced API-DLLs are missing (And adding them to my program is not allowed).
My question now is: how can i filter my listed types (either from assembly.GetTypes() or ReflectionTypeLoadException ex.Types) to remove those classes which actually use one of those missing API.DLLs (or use another class which use one of those etc.)? - assembly.GetReferencedAsseblies() only lists all referenced assemblies of my top level assembly. But as mentioned, this can contain multiply classes based on MyBaseClass, of which e.g. only one actually uses the missing API-DLL (defined by "using ..." at the start)
As an addition: can I automatically split my .CurrentDomain.AssemblyResolve event to their regarded top assemblies? Like having a (static?) resolve Method in each of my DLLs which handles missing sub-Assemblies instead of one method for all in my MainForm?
Thank you in advance!
Best regards, Robin
Aucun commentaire:
Enregistrer un commentaire