hope someone can help me, I've been searching, and haven't been able to find a solution. Might as well be something basic, I just can't find a solution.
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddJsonOptions(opt =>
{
opt.SerializerSettings.ReferenceLoopHandLing = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
});
This code is trying to fix a problem with reference looping. I'm following a tutorial on building a webapp with .NET and Angular CLI. On the tutorial, it's shown, the loop error, that I also got on my code. Trying to follow the solution (code above) I got an error on the SerializerSettings, saying that JsonOptions do not contain a definition for such.
I tried:
adding [Obsolete] (suggested by visual studio),
installing the Microsoft.AspNetCore.MVC.Formatters.Json nuget package (which VS informed it was doing nothing when added), (saw this solution on Documentation and Here com StackOverflow)
Tried ReferenceLoopHandling as for Newtonsoft Json.Net documentation (I might not have used it properly so if anyone feels this is the way out, please show me)
Thanks in Advance,
Solved.
services.AddMvc().AddNewtonsoftJson(o =>
{
o.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
Hope this helps.
NuGet: Microsoft.AspNetCore.Mvc.NewtonsoftJson
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With