You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System.Text.Json contract customization ignoring custom CreateObject delegates in certain collection types #73382
varoptions=newJsonSerializerOptions{TypeInfoResolver=newDefaultJsonTypeInfoResolver{Modifiers={static typeInfo =>{if(typeInfo.Type==typeof(IEnumerable<int>)){typeInfo.CreateObject=()=>newint[50];}}}}};varresult=JsonSerializer.Deserialize<IEnumerable<int>>("[]");Console.WriteLine(resultisint[]);// Prints "false"
This is because many collection converters are hardcoding their CreateObject implementation which ignores any user-defined delegates:
Note that this is currently not possible to fix unless we expose an API equivalent to the JsonCollectionConverter.Add method. For .NET 7 we should add detection for converters hardcoding CreateObject/Add implementations to specific types and have the JsonTypeInfo.CreateObject setter throw if not supported by the converter.
Activity