Click to See Complete Forum and Search --> : Assembly(System.Reflection) problem


tasoss
January 21st, 2010, 04:34 AM
Hello.
I'm using something like this


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!

boudino
January 21st, 2010, 05:19 AM
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.

tasoss
January 21st, 2010, 05:37 AM
You mean by simply using (Type)objRpt ?

mariocatch
January 21st, 2010, 10:48 AM
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.