I'm trying to get my hands around something that will tremendously simplify my code. If anyone knows a direction that would be of help, i would greatly appreciate it.
I'm loading plug-in DLLs, which have a C# wrapper, into the Assembly class of the System.Reflection Namespace. I can see the classes in the DLL that i need to access in the Types Array, in this case a class MyClass, and i can easily call it's methods in the MethodInfo Array with .Invoke(). But it would be very handy if i could cast from the Assembly to an instance of the class MyClass, and i haven't found a way to do that that works. I figured that the object returned from the Activator.CreateInstance() would be the perfect candidate, but it generates a runtime "Illegal cast" error. The object examined in Quickwatch in the Visual Studio IDE looks exactly like a MyClass, but it won't cast. Any ideas?
In addition, if anyone knows whether there's a way to pass a ref parameter into a MethodInfo.Invoke() that would also be helpful.