Link to home
Start Free TrialLog in
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();
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

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

Avatar of jackjohnson44
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
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial