-
January 21st, 2010, 04:34 AM
#1
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!
-
January 21st, 2010, 05:19 AM
#2
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.
Last edited by boudino; January 21st, 2010 at 05:19 AM.
Reason: typo
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post.
-
January 21st, 2010, 05:37 AM
#3
Re: Assembly(System.Reflection) problem
You mean by simply using (Type)objRpt ?
-
January 21st, 2010, 10:48 AM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|