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
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.
It might be possible to use the immediate window to serialize it and then copy the content to your favorite editor.
Another option is to override the ToString()
method and call it while in debug mode.
You can also write the contents out to a file shortly before the crash, or wrap the code into a try/catch and write the file then. I'm assuming you can identify when it's crashing.
I've been using ObjectDumper.Net.
It works well, especially if you have live unit testing. I can easily view a variable's value in the console when a test runs, saving me from debugging manually.
This may help if you're using XUnit.
In case you have a circular reference, run this in the immediate Window:
Newtonsoft.Json.JsonConvert.SerializeObject(app, Newtonsoft.Json.Formatting.Indented,
new Newtonsoft.Json.JsonSerializerSettings
{
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize
});