Issues with reflection parameters within VB.net

I'm having problems attempting to pass parameters that are gathered from various sources (XML, Database, etc). I have created an object array of the necessary parameters but i keep getting this error when trying to call the invoke option.

Object reference not set to an instance of an object.

It tells me to create a new instance of the object. I'm getting confused as I've stared at these lines of code for way too long.

Dim _params As New Object

                _params = parse_instructions(instructions(current_process).Split(","))

                'Set up the reflection call
                Dim objClass As Comms = Current_IOUnit.Current_Port
                Dim method As MethodInfo = objClass.GetType().GetMethod(current_process)

                'Call the function and save the value
                Return method.Invoke(objClass, _params)

Open in new window


Thanks
Ben
LVL 3
lazypeopleAsked:
Who is Participating?
 
käµfm³d 👽Connect With a Mentor Commented:
Set a breakpoint at line 10 and make sure that "method" is not null (nothing).
0
 
käµfm³d 👽Commented:
Which line causes the exception?
0
 
lazypeopleAuthor Commented:
line 10 when i try to pass the params
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
lazypeopleAuthor Commented:
method appears to be nothing what should it be filled with?

Thanks
Ben
0
 
lazypeopleConnect With a Mentor Author Commented:
Ignore me i've just seen what ive done i for got to cross reference the integer to the method name

thank you
0
 
käµfm³d 👽Commented:
I would say work backwards.

Since you got to line 10, that means line 7 succeeded. GetMethod(current_process) would have failed if GetType() had not returned a valid object, so the problem must lie with GetMethod. Try setting your breakpoint at line 7, then open the Immediate Window ( Ctrl-Alt-i ). Execute the following in the Immediate Window:

   ?objClass.GetType().GetMethod(current_process)

You will most likely see "Nothing". See if you can determine why GetMethod() is failing. It may be something to do with "current_process".
0
 
käµfm³d 👽Commented:
NP.  Glad you got it figured out  :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.