Non-static method requires a target

In my specific situation where I received this error, I was able to resolve it by simply changing “null” to the object containing the method which needed to be call.

This error indicates a use of reflections that can easily be confusing, but is very simple to resolve.

The specific resolution in the (StackOverflow) example in the referenced link below did not apply to my situation, but helped me quickly understand what caused the error and come to quick resolution by simply reading through the responses.

Example code from reference below:

public static T Test<T>(MyClass myClass) where T : MyClass2, new()
    var result = new T();

For specific code example where I encountered this message and how I was able to resolve, see the snippet below or my full post Call Parent Page from User Control.

Quick comparison where I encountered the error:

if (mi!=null) mi.Invoke(null, new Object[] {sender,e }); //throws indicated error

if (mi!=null) mi.Invoke(this.Page, new Object[] {sender,e }); //runs through clean

“Call Parent Page from User Control”,

About Ronnie Diaz

Ronnie Diaz is an enterprise software engineer responsible for front-end and back-end development for companies in many industries. Heavily involved in cloud development, online retail, e-commerce and electronic ordering, fulfillment and customer relational systems.

Posted on July 15, 2011, in Programming & Development and tagged , , , , , , , , , , , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: