Reflection

  • Thread starter Thread starter Roy Gourgi
  • Start date Start date
R

Roy Gourgi

Hi,

Someone suggested I try this, but I still get the error message:

No overload for method 'Invoke' takes '0' arguments
What am I doing wrong?
using System;

using System.Data;

using System.Data.Common;

using System.Data.SqlClient;

using System.Data.SqlTypes;

using System.Text;

using System.IO;

using System.Reflection;

class xxx

{

static void Main(string[] args)

{

string lcStr = "method1";

Type t = typeof(TestClass);

Console.WriteLine(t);

MethodInfo m = t.GetMethod(lcStr); // <- put your name here

Console.WriteLine(m);

Console.ReadLine();

//m.Invoke();

}



}



public class TestClass

{

public static void method1()

{

}

public static void method2()

{

}

public static void method3()

{

}

}



TIA

Roy
 
Roy Gourgi said:
Someone suggested I try this, but I still get the error message:

No overload for method 'Invoke' takes '0' arguments
What am I doing wrong?

Well, you're trying to call Invoke with no arguments, and there are no
overloads that don't take any arguments, as the compiler told you. Did
you look at the documentation for MethodInfo and find the Invoke
method?
 
Hi John,

Well I am trying to call method1 in the TestClass. This was the code
that was sent to me by Thomas Hulka and I just tried to run it but it
did not work.

What argument should I use with m.Invoke()?

Roy
 
Roy Gourgi said:
Well I am trying to call method1 in the TestClass. This was the code
that was sent to me by Thomas Hulka and I just tried to run it but it
did not work.

What argument should I use with m.Invoke()?

Two null arguments - one for the target and one for the parameters.

However, there's an important point here - the answer to your question
is in MSDN. You'll find it's usually a lot quicker to get answers to
questions like this from documentation than from newsgroups.
 
Hi Jon,

What do you mean by 2 null arguments? How would that be done?

Furthermore, where do I find the documentation to MSDN?

Thanks
Roy
 
Roy Gourgi said:
What do you mean by 2 null arguments? How would that be done?

m.Invoke(null, null);
Furthermore, where do I find the documentation to MSDN?

Well, are you using Visual Studio? If so, what happens if you press F1?

You can't hope to use .NET without the documentation in some form or
other. You *can* go online (msdn2.microsoft.com) but it's much better
to have it locally.
 
Back
Top