C# NewtonJson Self referencing loop detected for property 'Parent' with type

private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    string imgJson1 = JsonConvert.SerializeObject(img1);
    System.IO.File.AppendAllText($"{DateTime.Now.ToString("yyyyMMddHHmmssffff")}_img.json", imgJson1);
    //string imgJson1 = JsonConvert.SerializeObject(img1);
}

 

Updated

private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    var settings = new JsonSerializerSettings()
    {
        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
    };
    string imgJson1 = JsonConvert.SerializeObject(img1, Formatting.Indented, settings);
    System.IO.File.AppendAllText($"{DateTime.Now.ToString("yyyyMMddHHmmssffff")}_img.json", imgJson1);
    //string imgJson1 = JsonConvert.SerializeObject(img1);
}

 

 

 

 

var settings = new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
string imgJson1 = JsonConvert.SerializeObject(img1, Formatting.Indented, settings);

 

posted @ 2024-06-06 18:01  FredGrit  阅读(5)  评论(0编辑  收藏  举报