Thanks, this looks like a real bug. FWIW it's not specific to primary constructors or records, this fails too:
using System.Text.Json.Serialization;
using System.Text.Json;
var singleUserJson = """{"Username":"Filip","PhoneNumbers":["123456"]}""";
var userFromJson = JsonSerializer.Deserialize<User>(singleUserJson);
Console.WriteLine(userFromJson.PhoneNumbers.Count); // 0
public class User
{
public User(string name)
=> Name = name;
public string Name { get; }
[JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)]
public List<string> PhoneNumbers { get; } = new();
}
Originally posted by @eiriktsarpalis in dotnet/docs#37329 (comment)