AutoBogus
AutoBogus copied to clipboard
Record with nested children of the same type as the parent causes StackOverflow
It seems that the recursive depth safe mechanism doesn't work on records. Generating an instance of this record as follows
public record FakeChild (string Name, List<FakeChild>? C);
var child = new AutoFaker<FakeChild>().Configure(x => x.WithTreeDepth(1).WithRecursiveDepth(1)).Generate();
will cause a StackOverflow exception.
The only way around this is to move the Children
property to the Record body as follows:
public record FakeChild (string Name)
{
List<FakeChild> Children { get; set; }
}
While that works, it defies the purpose of using a Record instead of a Class.
I'm sure you have moved past this, but I will fix this in soenneker.utils.autobogus shortly
soenneker.utils.autobogus now supports classes and records with parameters of the same declaring type.