Assembly(System.Reflection) problem
Hello.
I'm using something like this
Code:
String classname = "";
Assembly rptAssembly = null;
Type rptObjType = null;
classname = Request["AssemblyName"] + "." + Request["className"];
rptAssembly = Assembly.LoadFrom(installDIR.ToString() + "\\" + this.Request["AssemblyName"] + ".dll");
rptObjType = rptAssembly.GetType(classname);
objRpt = rptObjType.InvokeMember(Request["className"], BindingFlags.CreateInstance, null, null, null);
The problem is that objRpt is an Object object so i cannot use the functions of the original class. I have tried the same thing in vb.net and it works(i suppose vb do the casting itself).
So how can i make objRpt a classname object so i can use its methods etc.
Thank you in advance!
Re: Assembly(System.Reflection) problem
If you know the type (are at least one of its predecestor, abstract class or interface), cast it to this. You can also use DLR comming with .NET 4.0.
Re: Assembly(System.Reflection) problem
You mean by simply using (Type)objRpt ?
Re: Assembly(System.Reflection) problem
No, you want to use Activator.CreateInstance<T>
This will give you back an instance of the Type you want, or an object that can be cast to the Type you want.