Visual Studio how to serialize object from debugger

后端 未结 10 1211
轻奢々
轻奢々 2020-12-22 16:39

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

10条回答
  •  抹茶落季
    2020-12-22 17:30

    I have an extension method I use:

    public static void ToSerializedObjectForDebugging(this object o, FileInfo saveTo)
    {
        Type t = o.GetType();
        XmlSerializer s = new XmlSerializer(t);
        using (FileStream fs = saveTo.Create())
        {
            s.Serialize(fs, o);
        }
    }
    

    I overload it with a string for saveTo and call it from the immediate window:

    public static void ToSerializedObjectForDebugging(this object o, string saveTo)
    {
        ToSerializedObjectForDebugging(o, new FileInfo(saveTo));
    }
    

提交回复
热议问题