The root cause of the problem is as yet not fully understood, but I do know how I fixed it.
After poke taught me how to look at the ASP.NET Core logs, I discovered this exception:
System.Text.Json.JsonException: A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles.
Researching that lead me to several resources:
The solution may be that I should refactor my code to use DTOs (something I'll have to read up on because I don't understand that yet). In the meantime, the bandaid that will allow me to proceed is:
- Install NuGet Package
Microsoft.AspNetCore.Mvc.NewtonsoftJson
- In
Statup.cs
in ConfigureServices
add
services.AddControllers().AddNewtonsoftJson(options =>
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
Thank you to everyone who helped me think through this. I greatly appreciate your assistance!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…