Json.NET Serializing Run抛出StackOverflowException

时间:2015-01-21 04:18:21

标签: c# json.net stack-overflow

我正在尝试序列化System.Windows.Documents.Run对象,而JsonConvert.SerializeObject()会抛出StackOverflowException,即使ReferenceLoopHandling设置为Ignore也是如此。如何序列化Run对象?

触发线:

string test = JsonConvert.SerializeObject(new Run("testing"), 
    new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });

1 个答案:

答案 0 :(得分:-1)

try
{
var _run = new Run()
}
catch (Exception ex)
{
//serialize your erorr
}
finally
{
//impossible but still
if (_run != null)
{
//serialize _run
}
}

如果对象创建失败,则无法序列化null对象。