Object reference not set to an instance of an object error

PSCTECH used Ask the Experts™
I have the following code which is throwing an "object reference not set to an instance of an object error".  How can I change it to not give this exception?  The code is supposed to check for SecondaryWageAmount and if it's there, add it to PrimaryWageAmount otherwise just return PrimaryWageAmount

            decimal returnValue;
            returnValue = HasSecondary ?
                               PrimaryWageAmount + SecondaryWageAmount
                            : PrimaryWageAmount;
            return returnValue;

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014
What are HasSecondary, PrimaryWageAmount and SecondaryWageAmount?
At least one of them is null or is a property which uses a null object at some point. Which one?


Actally, I figured it out.  You are right  SecondaryWageAmount was erroneously getting set to null.  Thanks for the response


Thanks for the quick response.  I appreciate it.
Are you certain that the error is happening on this section of code? Your exception... is it indicating that the error is on these lines?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial