Serializing null recursive IEnumerable with JsonSerializer causes StackOverflowException
When serializing an object that contains recursive IEnumerable member of itself, JsonSerializer.Serialize throws an StackOverflowException.
Error isn't thrown if using for example concrete List-class instead of IEnumerable.
.NET Core 3.0.100-preview8-013656 OS: Windows 10, 1903
Sample code:
namespace TestConsoleApp
{
using System.Collections.Generic;
using System.Text.Json;
public static class Program
{
public static void Main()
{
var model = new Node();
System.Console.WriteLine(JsonSerializer.Serialize(model));
}
}
public sealed class Node
{
public IEnumerable<Node> Children { get; set; }
}
}
Expected result: {"Children": null}
maybe @ahsonkhan can help on this?
No repro for me in Preview 9 builds. Try the following:
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="4.6.0-preview9.19421.4" />
</ItemGroup>
Or install a preview9 build from https://github.com/dotnet/core-sdk
Believe this is a dup of https://github.com/dotnet/corefx/issues/40050 and https://github.com/dotnet/corefx/issues/39769 /cc @steveharter
Thanks for the report!