By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,682 Members | 1,980 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,682 IT Pros & Developers. It's quick & easy.

LCE Late Bind

P: n/a
Hi,

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

The main executable codes look like this:
Assembly asm = Assembly.LoadFile(@"C:\ClassLibrary1.dll");
Type typ = asm.GetType("INPTest.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
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> Can anyone show some examples using the same concept without the static
keyword?


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

Assembly asm = Assembly.LoadFile(@"C:\ClassLibrary1.dll");
Type typ = asm.GetType("INPTest.Class1");

object o = Activator.CreateInstance( typ );
typ.InvokeMember( "Show", BindingFlags.InvokeMethod, null, o, null );

regards,
Wiktor Zychla
Nov 16 '05 #2

P: n/a
Thanks Wiktor

"Wiktor Zychla" wrote:
Can anyone show some examples using the same concept without the static
keyword?


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

Assembly asm = Assembly.LoadFile(@"C:\ClassLibrary1.dll");
Type typ = asm.GetType("INPTest.Class1");

object o = Activator.CreateInstance( typ );
typ.InvokeMember( "Show", BindingFlags.InvokeMethod, null, o, null );

regards,
Wiktor Zychla

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.