Avatar of jackjohnson44
jackjohnson44
 asked on

linq how to debug selecting objects into new objects

Hi,
I have a ton of xml web service responses which were converted into classes.  There are a few issues with these as we are seeing.  I commonly do something like the following to display some classes in a grid.  Sometimes depending on the input, everything blows up "Object reference not set to an instance of an object.".  When this happens, how can i go about trying to debug this?  I am guessing there is a null value or something.  I am looking for something reusable.

Thanks!


                var results = (from os in orderStatus.orderstatus
                               select new
                               {
                                   orderNumber = os.orderNumber,
                                   reportedTime = os.reportedTime,
                                   orderstring = os.orderstring,
                                   symbol = os.order.symbol,
                                   quantity = os.order.quantity,
                               }).ToList();
C#.NET Programming

Avatar of undefined
Last Comment
Meir Rivkin

8/22/2022 - Mon
Meir Rivkin

change it to this:
   var results = (from os in orderStatus.orderstatus
                               select new
                               {
                                   orderNumber = os.orderNumber,
                                   reportedTime = os.reportedTime,
                                   orderstring = os.orderstring,
                                   symbol = os.order ! =null ? os.order.symbol : null,
                                   quantity = os.quantity != null ? os.order.quantity : null,
                               }).ToList();

Open in new window

jackjohnson44

ASKER
Thanks, I am more looking for a way to determine which element is having the issue.  i have several of these and want to know what the issue is instead of just checking for null on each element.
ASKER CERTIFIED SOLUTION
Meir Rivkin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23