Visual Studio how to serialize object from debugger

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)


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#


Some time ago I wrote this one-liner serializing an object to a file on the disk. Copy/paste it to your Immediate window, and replace obj (it's referenced twice) with your object. It'll save a text.xml file to c:\temp, change it to your liking.

(new System.Xml.Serialization.XmlSerializer(obj.GetType())).Serialize(new System.IO.StreamWriter(@"c:\temp\text.xml"), obj)

Don't expect any magic though, if the object cannot be serialized, it'll throw an exception.