# System.Text.Json.JsonException: 检测到可能的对象循环。这可能是由于循环引用或对象深度超过最大允许深度 64。

- **ID:** `dotnet/aspnetcore-json-cycle`
- **领域:** dotnet
- **类别:** serialization_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

JsonSerializer 在对象图中遇到循环引用（例如导航属性相互引用）或嵌套深度超过默认限制。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| dotnet 6.0 | active | — | — |
| dotnet 8.0 | active | — | — |
| System.Text.Json 6.0 | active | — | — |
| System.Text.Json 8.0 | active | — | — |

## 解决方案

1. ```
   Configure System.Text.Json to handle reference loops using ReferenceHandler.Preserve. Example in Program.cs.
   ```
2. ```
   Use DTOs or view models that flatten the object graph, avoiding circular references.
   ```
3. ```
   Set ReferenceHandler.IgnoreCycles to ignore navigation properties that cause cycles.
   ```

## 无效尝试

- **** — Does not break the cycle; serializer will still fail with stack overflow or infinite loop. (90% 失败率)
- **** — May hide needed data; can break client-side functionality if important relationships are omitted. (70% 失败率)
- **** — Newtonsoft.Json also has a default reference loop handling that throws; needs explicit configuration. (80% 失败率)
