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);