Solved

Issues with reflection parameters within VB.net

Posted on 2010-09-20
7
289 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 74

Expert Comment

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

Author Comment

by:lazypeople
Comment Utility
line 10 when i try to pass the params
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
Set a breakpoint at line 10 and make sure that "method" is not null (nothing).
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Author Comment

by:lazypeople
Comment Utility
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
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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 74

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

771 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