CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Jul 2002
    Posts
    30

    Lightbulb 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!

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    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.

  3. #3
    Join Date
    Jul 2002
    Posts
    30

    Re: Assembly(System.Reflection) problem

    You mean by simply using (Type)objRpt ?

  4. #4
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    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
  •  





Click Here to Expand Forum to Full Width

Featured