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
Deserializing a record instance is causing child elements to be duplicated when using configuration binder Get<T> method #1451
When deserializing the configuration using the binder via configurationRoot.Get() method, some of the child elements are duplicated.
In the below code snipped:
using Microsoft.Extensions.Configuration;
using System.Text.Json;
public static class Program
{
public static void Main()
{
var sample1 = new Root("root1", [new("c1", "c1n1", "c1n1value")]);
var sampl1Json = sample1.ToJson();
//Console.WriteLine(sampl1Json);
var cbjson = new ConfigurationBuilder()
//.AddJsonFile("appsettings.json", optional: false)
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(sampl1Json)))
.Build();
var sample1copy = cbjson.Get<Root>();
var sample1copyJson = sample1copy.ToJson();
Console.WriteLine(sample1copyJson);
}
public record Root(string Id, ChildElement[] Elements);
public record ChildElement(string Id, string Name, string Value);
}
file static class Utils
{
static readonly JsonSerializerOptions _SERIALIZER = new()
{
WriteIndented = true
};
public static string ToJson<T>(this T obj) => JsonSerializer.Serialize<T>(obj, _SERIALIZER);
}
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.100-rc.2.24474.11\
Activity
rajasekarshanmugam commentedon Oct 23, 2024
moved to dotnet/runtime#109139