EXCEPTION: 2025-07-17 11:30:13.161 +00:00 [ERR] ---------- RemoteServiceErrorInfo ---------- { "code": null, "message": "InternalServerErrorMessage", "details": null, "data": {}, "validationErrors": null }
2025-07-17 11:30:13.162 +00:00 [ERR] 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 64. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles. Path: $.Principal.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Issuer. 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 64. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles. Path: $.Principal.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Subject.Claims.Issuer.
I found this support ticket https://abp.io/support/questions/8143/A-cycle-during-the-cache-serialization but is not clear how to configure it.
Could you attach an example please?
5 Answer(s)
-
0
To resolve the "A possible object cycle was detected" error during external login in ABP, you need to configure the JSON serializer to handle object cycles. In .NET, this is typically done by setting
ReferenceHandler.Preserve
onJsonSerializerOptions
. In ABP Blazor WASM projects, you can configure this globally for your application.Here is an example of how to configure the JSON serializer to use
ReferenceHandler.Preserve
in your Blazor WASM project:Configure in Program.cs (Blazor WASM Client):
using System.Text.Json; using System.Text.Json.Serialization;
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.Configure
2. **Configure in Startup (Server Side, if applicable):** If you have a server-side (API) project, configure the JSON options in `Startup.cs` or `Program.cs`: ```csharp services.AddControllers() .AddJsonOptions(options => { options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve; options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; });
- Restart your application after making these changes.
This configuration will allow the serializer to handle object cycles and prevent the exception you encountered.
Sources:
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
-
0
In the Program.cs of blazor client or in my host module?
-
0
hi
Could you please share the code that reproduces this exception?
Thanks.
-
0
We cannot share that code because is our enterprise production code. As i said we've seen this closed ticket https://abp.io/support/questions/8143/A-cycle-during-the-cache-serialization so we guess that the solution for it will do, we only need how to configure it exactly.
-
0
hi
we only need how to configure it exactly.
You need to configure JSON options in two places.
// This is for MVC JsonSerializer Configure<JsonOptions>(options => { options. }); // This is for ABP JsonSerializer Configure<AbpSystemTextJsonSerializerOptions>(options => { options. });