- ABP Framework version: v8.1.3
- UI Type: Angular
- Database System: EF Core (Oracle)
- Auth Server Separated OpenID Server
How to avoid this error or even a warning?
WRN (admin) 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: $.MyObject.Equipment.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Location.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: $.MyObject.Equipment.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Component.Configurations.Location. at System.Text.Json.ThrowHelper.ThrowJsonException_SerializerCycleDetected(Int32 maxDepth) at System.Text.Json.Serialization.JsonConverter
1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo
1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter
1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.Metadata.JsonTypeInfo1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed) at System.Text.Json.Serialization.Metadata.JsonTypeInfo
1.SerializeAsObject(Utf8JsonWriter writer, Object rootValue) ... at Volo.Abp.Json.SystemTextJson.JsonConverters.ObjectToInferredTypesConverter.Write(Utf8JsonWriter writer, Object objectToWrite, JsonSerializerOptions options) at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.JsonConverter
1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) at System.Text.Json.Serialization.Metadata.JsonTypeInfo1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed) at System.Text.Json.JsonSerializer.WriteString[TValue](TValue& value, JsonTypeInfo
1 jsonTypeInfo) at Volo.Abp.Caching.Utf8JsonDistributedCacheSerializer.Serialize[T](T obj) at Volo.Abp.Caching.DistributedCache`2.<>c__DisplayClass51_0.<
Please make note that I already use this setting in my HttpApiHostModule
:
private static void ConfigureSerialization(ServiceConfigurationContext context)
{
context.Services.AddControllers().AddJsonOptions(x => x.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles);
}
But obviously it is not enough for the cache.
Another note is that I really have navigation properties in both cases and I do use them in the EntityFramework code. I just want to exclude circular from the consideration, i.e. if I take component.Configurations
- I do not want to read Component
from each Configuration
and if take configuration.Component
- I do not want further read Configurations
of each Component
.
3 Answer(s)
-
0
hi
You can try to configure the
AbpSystemTextJsonSerializerOptions
to set theJsonSerializerSettings
https://abp.io/docs/latest/framework/infrastructure/json#abpsystemtextjsonserializeroptions
-
0
hi
You can try to configure the
AbpSystemTextJsonSerializerOptions
to set theJsonSerializerSettings
https://abp.io/docs/latest/framework/infrastructure/json#abpsystemtextjsonserializeroptions
Are you sure it's
JsonSerializerSettings
, notJsonSerializerOptions
? Because as far as I understand,JsonSerializerSettings
is related toNewtonsoft.Json
, notSystem.Text.Json
fromMicrosoft
. And the exception is related to the latter.Besides, where do you suggest to place it?
public class MyHttpApiModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { ... Configure<JsonOptions>(options => { options.JsonSerializerOptions.Converters.Add(context.Services.GetRequiredService<IStringToNullableIntConverter>() as JsonConverter); options.JsonSerializerOptions.Converters.Add(context.Services.GetRequiredService<IStringToNullableLongConverter>() as JsonConverter); options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; //Maybe this will help? }); Configure<AbpSystemTextJsonSerializerOptions>(options => { //The change is here? }); } }
-
0
hi
You are right. The property is
JsonSerializerOptions
https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Json.SystemTextJson/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonSerializerOptions.cs#L7
You can configure it in your host module/project.
eg: API.Host