Visual Studio how to serialize object from debugger

xvorsx picture xvorsx · Sep 13, 2013 · Viewed 39.2k times · Source

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?

Answer

mcintyre321 picture mcintyre321 · Apr 29, 2014

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)