I'm trying to investigate a bug in a crash dump (so I can not change the code). I have a really complicated object (thousands of lines in the serialized representation) and its state is inconsistent. To investigate its state the Visual Studio debugger view is useless. But the object has a data contract. I'd like to serialize it and then use my favorite text editor to navigate across the object. Is it possible to do the from the debugger?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
A variation on Alexey's answer. Slightly more complicated but doesn't involve writing to a text file:
1) In the Immediate Window enter:
2) In the Watch Window enter two watches:
After you enter the second watch (the Serialize one) the stringWriter watch value will be set to obj serialized to XML. Copy and paste it. Note that the XML will be enclosed in curly braces, {...}, so you'll need to remove them if you want to use the XML for anything.
Here is a Visual Studio extension which will let you do exactly that:
https://visualstudiogallery.msdn.microsoft.com/c6a21c68-f815-4895-999f-cd0885d8774f
You can output to JSON, XML or C#
I have an extension method I use:
I overload it with a string for saveTo and call it from the immediate window:
With any luck you have Json.Net in you appdomain already. In which case pop this into your Immediate window:
Newtonsoft.Json.JsonConvert.SerializeObject(someVariable)
A variation on the answer from Omar Elabd --
It's not free, but there's a free trial for OzCode
(https://marketplace.visualstudio.com/items?itemName=CodeValueLtd.OzCode).
There's built-in exporting to JSON within the context/hover menu there, and it works a bit better than the Object Export extension (the trade-off for it not being free).
http://o.oz-code.com/features#export (demo)
I know this is a few years after the fact, but I'm leaving an answer here because this worked for me, and someone else may find it useful.
Some time ago I wrote this one-liner serializing an object to a file on the disk. Copy/paste it to your Intermediate window, and replace
obj
(it's referenced twice) with your object. It'll save the text.xml file to c:\temp, change it to your liking.Don't expect any magic though, if the object cannot be serialized, it'll through an exception.