conditionally load managed DLL

bwells

Regular
Joined
Feb 25, 2003
Messages
84
In my C# application, I want to decide at run time to load a managed DLL based on user input. I have a factory that returns an object that implements an interface, and the kind of object the factory will instantiate should be based on user input, as well as if the factory can find a particular managed DLL in the local directory.

If the user enters a particular value, and a matching DLL can be found, then the factory will load the DLL and instantiate an object from the DLL. If the DLL cannot be found, then the factory will load a "default" managed DLL and instantiate a dummy object which implements the expected interface.

What is the best way to do what I have described?

Bryan
 
I would use the LoadFrom method of the Assembly class (in the Reflection namespace) and then use its CreateInstance method.
 
Back
Top