Your data contains a loop

An item contains itself, directly or through other items, so it cannot be saved.

  • Error
  • BEVEL051

What it means

JSON cannot store a loop, such as a post that holds an author who holds the same post.

Example message

text
Data/Posts/BlogPost.cs(6,15): error BEVEL051: Dataset 'Posts' (CLR type 'IReadOnlyList<BlogPost>') cannot be frozen: its object graph has a cycle or is nested deeper than the serializer allows (A possible object cycle was detected). Break the cycle (e.g. keep only a key on the back-reference and mark it [JsonIgnore], or use [Reference] to link items by key), or flatten the data. Help: https://khalidabuhakmeh.github.io/bevel/reference/diagnostics/bevel051/

How to fix

Break the loop. Keep only a key on the back-reference, or link items with [Reference].

csharp
public sealed record Author(string Slug)
{
    public List<BlogPost> Posts { get; init; }
    [JsonIgnore]
    public List<BlogPost> Posts { get; init; }
}