lazypeople
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.
Thanks
Ben
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)
Thanks
Ben
Which line causes the exception?
ASKER
line 10 when i try to pass the params
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
method appears to be nothing what should it be filled with?
Thanks
Ben
Thanks
Ben
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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().GetMet hod(curren t_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".
Since you got to line 10, that means line 7 succeeded. GetMethod(current_process)
?objClass.GetType().GetMet
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 :)