.NET CORE 3 Upgrade CORS and Json(cycle) XMLHttpRequest Error

The problem was occurring because in .NET Core 3 they change little bit the JSON politics. Json.Net is not longer supported and if you want to used all Json options, you have to download this Nuget: Microsoft.AspNetCore.Mvc.NewtonsoftJson.

After that in your Startup.cs file change/fix/add line where you are adding MVC (in the ConfigureServices method.

So: here is what I did and what fixed my issue:

services.AddMvc(option => option.EnableEndpointRouting = false)
                .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
                .AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);

I hope it will help somebody else. Cheers!


A couple other things have changed in .net core 3 and now instead of using addMVC you can use addControllers. So your code might look like the follow:

services.AddControllers().AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);