LCE Late Bind

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • C# Newbie

    LCE Late Bind

    Hi,

    I have a Class1.cs and a Main executable file.

    The main executable codes look like this:
    Assembly asm = Assembly.LoadFi le(@"C:\ClassLi brary1.dll");
    Type typ = asm.GetType("IN PTest.Class1");
    MethodInfo mi = typ.GetMethod(" Show");
    mi.Invoke(asm, null);

    The Class1.cs codes look like this:
    public static void Show()
    {
    MessageBox.Show ("Create Log");
    }

    If I remove the static from the Show method I will have the error message
    displayed --> Object does not match target type.

    Can anyone show some examples using the same concept without the static
    keyword?

    Thanks,
    C# newbie
  • Wiktor Zychla

    #2
    Re: LCE Late Bind

    > Can anyone show some examples using the same concept without the static[color=blue]
    > keyword?[/color]

    to call non-static methods you need an object instance and invoke the method
    against the instance.

    Assembly asm = Assembly.LoadFi le(@"C:\ClassLi brary1.dll");
    Type typ = asm.GetType("IN PTest.Class1");

    object o = Activator.Creat eInstance( typ );
    typ.InvokeMembe r( "Show", BindingFlags.In vokeMethod, null, o, null );

    regards,
    Wiktor Zychla


    Comment

    • C# Newbie

      #3
      Re: LCE Late Bind

      Thanks Wiktor

      "Wiktor Zychla" wrote:
      [color=blue][color=green]
      > > Can anyone show some examples using the same concept without the static
      > > keyword?[/color]
      >
      > to call non-static methods you need an object instance and invoke the method
      > against the instance.
      >
      > Assembly asm = Assembly.LoadFi le(@"C:\ClassLi brary1.dll");
      > Type typ = asm.GetType("IN PTest.Class1");
      >
      > object o = Activator.Creat eInstance( typ );
      > typ.InvokeMembe r( "Show", BindingFlags.In vokeMethod, null, o, null );
      >
      > regards,
      > Wiktor Zychla
      >
      >
      >[/color]

      Comment

      Working...