Problem invoking method with reflection

R

Rotsey

Hi,

I am getting a Exception has been thrown by the target of an invocation
error when invoking a method

Here is the crux of the code.

I realise it could be a few things, any one give me an idea where
to start looking.

rotsey

object obj;

Type type;

type = Type.GetType("TBR.NET." + formdef.TableName);

obj = Activator.CreateInstance(type);

if (obj == null)

throw new ApplicationException("Cannot create object for type " +
formdef.TableName);

int retval = (int)type.InvokeMember("Update",
BindingFlags.InvokeMethod,null, obj, null);
 
A

Alberto Poblacion

Rotsey said:
I am getting a Exception has been thrown by the target of an invocation
error when invoking a method

Typically this means that you succeeded in calling the method, but
something failed inside that method and threw an exception. Take a look at
the InnerException inside the Exception that you received to find out more
about what failed inside your method.
 
J

Jon Skeet [C# MVP]

I am getting a Exception has been thrown by the target of an invocation
error when invoking a method

Obvious next question: what does the inner exception say? That should
make it a lot clearer what's going wrong.

Jon
 
R

Rotsey

of course. bit slow today soory

Jon Skeet said:
Obvious next question: what does the inner exception say? That should
make it a lot clearer what's going wrong.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top