Wednesday, April 15, 2020

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.

Import Microsoft.AspNetCore.Mvc.NewtonsoftJson into Startup.cs and then make a stitch like so:

services.AddMvc(options =>
{
   options.Filters.Add(new ValidateComponentIdentifier());
   options.Filters.Add(new BubbleUpExceptions());
}).AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling =
      Newtonsoft.Json.ReferenceLoopHandling.Ignore);

 
 

It is the last line above (well, the last two really) that is most important.

No comments:

Post a Comment