Link to home
Start Free TrialLog in
Avatar of lazypeople
lazypeopleFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of kaufmed
kaufmed
Flag of United States of America image

Which line causes the exception?
Avatar of lazypeople

ASKER

line 10 when i try to pass the params
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
method appears to be nothing what should it be filled with?

Thanks
Ben
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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".
NP.  Glad you got it figured out  :)