Why NullReferenceException warning inside try...catch?

In the code snippet in the attached file, nothing I tried would remove the NullReferenceException warning on vehicle.SelectSingleNode("f[@n='DLRStockID']").

I would think rapping the block in a try...catch would have been sufficient to remove that warning.

What am I missing?

David Holt

1 comment
Comment actions Permalink

The try/catch handles the exception, but does not prevent it.  To prevent it, check the return value of vehicle.SelectSingleNode("f[@n='DLRStockID']") for null.

    var n = vehicle.SelectSingleNode("f[@n='DLRStockID']");
    if(n == null)
        stockId = "N/A";


Please sign in to leave a comment.