G
Guest
Hi,
I'm trying to instantiate a class from a precompiled assembly .dll and cast it into a known Interface typ
// Load the assembl
Assembly externalAssembly = Assembly.LoadFrom("some.dll")
// Create The typ
Type externalType = externalAssembly.GetType("My.Created.UserClass")
//Create the objec
IView exView = (IView) Activator.CreateInstance(externalType)
My.Created.UserClass is the fully qualified name for the class, and it extends UserControl and implements IView interface in which I created. I was able to compile this fine but when I get "Specified Cast Not Valid" error in runtime
I need to do this because I have to run a Configure() method which is a member of the IView interface. I know I can make a MethodInfo and assign Configure to it, but I really dont want to because of design requirements. A weird thing I noticed is that the code runs if I instead cast the Activator.CreateInstance(..) into a UserControl Object
Thank you
Rizka Armadhan
I'm trying to instantiate a class from a precompiled assembly .dll and cast it into a known Interface typ
// Load the assembl
Assembly externalAssembly = Assembly.LoadFrom("some.dll")
// Create The typ
Type externalType = externalAssembly.GetType("My.Created.UserClass")
//Create the objec
IView exView = (IView) Activator.CreateInstance(externalType)
My.Created.UserClass is the fully qualified name for the class, and it extends UserControl and implements IView interface in which I created. I was able to compile this fine but when I get "Specified Cast Not Valid" error in runtime
I need to do this because I have to run a Configure() method which is a member of the IView interface. I know I can make a MethodInfo and assign Configure to it, but I really dont want to because of design requirements. A weird thing I noticed is that the code runs if I instead cast the Activator.CreateInstance(..) into a UserControl Object
Thank you
Rizka Armadhan