Edit: I would like to keep the infrastructure as is, so while the framework ideas are appreciated, please keep your suggestions centered on the context I have provided.
Background
I'm building a web-based application that dynamically loads plugins. Each plugin comes with a manifest file that contains its dll location, namespace, and type.
Right now I'm using System.Reflection.Assembly.LoadFile
to load up the dlls based off the locations provided in the manifest files. Then I load the types and so on.
As an Aside:
I may wind up changing to System.Reflection.Assembly.LoadFrom
since I'll eventually be loading files from outside the bin directory. But if their is a better way (Assembly.Load
or something), feel free to add that in as well
Problem
The problem is that Multiple plugins can potentially run off the same dll. So I wind up executing System.Reflection.Assembly.LoadFile("Identical.dll")
multiple times.
I have the idea to check if my assembly has already been loaded by iterating through AppDomain.CurrentDomain.GetAssemblies()
, but I don't know if that will help with performance (or if it will work period, I haven't tried it).
Also, I can't keep a list of loaded assemblies due to the project's design constraints (though you may argue that it's a poor design: I can't change it, even if I wanted to OR agreed with you... so please don't press the issue....... please..... unless you really feel that strongly about it, I guess you can add that in as a suggestion).
Ultimately my goals are:
- Don't ever re-load the same assembly twice.
- Performance is key.