Copy object values in Visual Studio debug mode

You can run below code in immediate window and it will export to an xml file the serialized XML representation of an object:

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

Source: Visual Studio how to serialize object from debugger


In the immediate window, type

?name_of_variable

This will print out everything, and you can manually copy that anywhere you want, or use the immediate window's logging features to automatically write it to a file.

UPDATE: I assume you were asking how to copy/paste the nested structure of the values so that you could either search it textually, or so that you can save it on the side and then later compare the object's state to it. If I'm right, you might want to check out the commercial extension to Visual Studio that I created, called OzCode, which lets you do these thing much more easily through the "Search" and "Compare" features.

UPDATE 2 To answer @ppumkin's question, our new EAP has a new Export feature allows users to Export the variable values to Json, XML, Excel, or C# code.

Full disclosure: I'm the co-creator of the tool I described here.