我正在尝试序列化System.Windows.Documents.Run
对象,而JsonConvert.SerializeObject()会抛出StackOverflowException,即使ReferenceLoopHandling设置为Ignore也是如此。如何序列化Run对象?
触发线:
string test = JsonConvert.SerializeObject(new Run("testing"), new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
答案 0 :(得分:-1)
try
{
var _run = new Run()
}
catch (Exception ex)
{
//serialize your erorr
}
finally
{
//impossible but still
if (_run != null)
{
//serialize _run
}
}
如果对象创建失败,则无法序列化null对象。