newtonsoft self referencing loop detected with type code example
Example 1: Newtonsoft.Json.JsonSerializationException: 'Self referencing loop detected for property
var settings = new Newtonsoft.Json.JsonSerializerSettings();
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
return JsonConvert.SerializeObject(<Your Object>, settings);
Example 2: asp.net core api Self referencing loop detected for property
public class StaffMember
{
public string FirstName { get; set; }
public virtual Department Department { get; set; }
}
public class Department
{
public string DepartmentName { get; set; }
[JsonIgnore]
public virtual ICollection StaffMembers { get; set; }
}