Solve: A possible object cycle was detected which is not supported

System.Text.Json.JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. at ……

3

work well after installing the package Microsoft.AspNetCore.Mvc.NewtonsoftJson firstly for 3.0 or higher.

services.AddControllersWithViews()
    .AddNewtonsoftJson(options =>
    options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
);

Try with a new project and compare the differences.

Leave a Comment

Your email address will not be published.