Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

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
0
lazypeople
Asked:
lazypeople
  • 4
  • 3
2 Solutions
 
käµfm³d 👽Commented:
Which line causes the exception?
0
 
lazypeopleAuthor Commented:
line 10 when i try to pass the params
0
 
käµfm³d 👽Commented:
Set a breakpoint at line 10 and make sure that "method" is not null (nothing).
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

Thanks
Ben
0
 
lazypeopleAuthor 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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now