“Self Referencing Loop Detected” exception with JSON.Net

The meaning of the error message is that there is a self referencing loop. You have to set the db context that you do not want to get all linked entities when you request some entities. It can be done by adding two lines into DbContext class constructor to disable self referencing loop as shown below:

public YourDbContext() : base("name = YourDbContext")
{       
    //add these lines in order to avoid from "Self referencing loop detected for ..." error
    this.Configuration.LazyLoadingEnabled = false;
    this.Configuration.ProxyCreationEnabled = false;
}

Hope this helps…

Leave a Comment