Solved

Issues with reflection parameters within VB.net

Posted on 2010-09-20
7
291 Views
Last Modified: 2013-12-12
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
Comment
Question by:lazypeople
  • 4
  • 3
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 33717921
Which line causes the exception?
0
 
LVL 3

Author Comment

by:lazypeople
ID: 33717953
line 10 when i try to pass the params
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 33718029
Set a breakpoint at line 10 and make sure that "method" is not null (nothing).
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 3

Author Comment

by:lazypeople
ID: 33718087
method appears to be nothing what should it be filled with?

Thanks
Ben
0
 
LVL 3

Assisted Solution

by:lazypeople
lazypeople earned 0 total points
ID: 33718134
Ignore me i've just seen what ive done i for got to cross reference the integer to the method name

thank you
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 33718161
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 33718168
NP.  Glad you got it figured out  :)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How would I do a website like this? 5 52
SQL LINE CONTINUATION ISSUE 12 31
VB.NET - Error - Object not set in Module 4 33
Write to a printer using vb.net 9 19
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now