How can you easily watch the contents of the Data property of an Exception in the Watch Window while debugging in Visual Studio? It is of the weird type System.Collections.ListDictionaryInternal.
I figured out you can see the Keys and Values separately:
try {
... do something that throws exception with Data
}
catch (Exception ex) {
throw;
}
finally {
}
In the Watch window:
ex.Data.Keys.Cast<string>()
ex.Data.Values.Cast<string>()
But can you view it as a dictionary or something?
System.Collections.ListDictionaryInternal
is an IDictionary, so you could just evaluate the following expression in the Watch or QuickWatch window:
new System.Collections.Hashtable(ex.Data)
Edit: I co-created a commercial extension for Visual Studio called OzCode that makes this a lot easier. With it, you can simply hover over the Exception variable, right click it, choose Create Custom Expression, and type in new System.Collections.Hashtable([obj].Data) // Data
. From that moment on, whenever you view an Exception, you'll be able to see its Data dictionary in a nicely formatted way without any manual steps, like so:
I think your best bet is to create a function to output the Exception content, including the Data elements, if any, to the Output window using System.Diagnostics.Debug.Write()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With