Once you have a reference to a loaded assembly, you can create an instance of a class in the assembly. The only problem is that the function that lets you do this has a return type of object. Of course it needs to use object as its return type since you can use the function to create any class. However, this doesn't help us much, since we can only make calls for methods in the object class. We could cast the variable to a more concrete type, but in order to do a cast we need to have the type defined ahead of time, and that means we need to have a reference to the assembly containing the type. Having a reference to the assembly sort of defeats the whole purpose of loading an assembly dynamically. The answer to this is to use interfaces. The sample application uses this approach. It puts the definitions for the interfaces in a separate DLL. Then the Web application has a reference to the interface DLL. When we load an assembly dynamically and create an object, we can cast the object to the interface type. This makes it possible for us to use the object through the interface methods. To create an instance of a class in an assembly:
Tip
|