class Program
{
static void Main(string[] args)
{
var json = "[1, 2]";
var x = JsonSerializer.Deserialize<CustomList<int>>(json);
}
}
public class CustomList<T> : List<T>
{
public CustomList(int x) { }
}
Stack trace:
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at System.Text.Json.ReadStackFrame.CreateEnumerableValue(Utf8JsonReader& reader, ReadStack& state)
at System.Text.Json.JsonSerializer.HandleStartArray(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)
at System.Text.Json.JsonSerializer.ReadCore(Type returnType, JsonSerializerOptions options, Utf8JsonReader& reader)
at System.Text.Json.JsonSerializer.ParseCore(String json, Type returnType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
Reproduced using Microsoft.NETCore.App 3.0.0-rc1-19456-20
Adding a parameterless ctor works, but the exception message likely needs to say that a parameterless ctor needs to be declared.
Stack trace:
Reproduced using
Microsoft.NETCore.App 3.0.0-rc1-19456-20Adding a parameterless ctor works, but the exception message likely needs to say that a parameterless ctor needs to be declared.