-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuration binding with nested types and readonly properties not working #77677
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsDescriptionWith #67258 the binding of immutable types is working but with nested types seams not to work. Reproduction Stepspublic record RootConfig(NestedConfig Nested);
public record NestedConfig(string MyProp);
public RootConfig GetConfiguration()
{
IConfiguration configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string?>
{
{ "Nested:MyProp", "Dummy" }
})
.Build();
return configuration.Get<RootConfig>();
} In the above case the following exception will be thrown:
If the public record RootConfig
{
public NestedConfig Nested { get; init; }
} Expected behaviorNo exception. Actual behaviorThrows Regression?No response Known WorkaroundsDeclare the Configuration.NET 7 RC2 Other informationNo response
|
@SteveDunn will you have some spare time to look at this one? |
@tarekgh / @glucaci - hi - I just got main and added this test and it passed without the exception described above Admittedly, this was a very quick exercise as my time is rather limited with my day job. Have I missed something? (PR added - please feel free to modify it so that it breaks, and I'll attempt a fix when time permits - #77693) |
@SteveDunn thanks for the follow up. I am trying that with .NET 7.0 rc2 and I am seeing it failing. I'll try the rtm bits to see if it reproduces there.
|
Interesting, it looks something has been changed in .NET 8.0 which fixed the issue. We need to understand what has changed. |
Actually, it might be worth merging in as the test is useful as a regression. |
Agree. Thanks for pointing at the change that fixed this issue.
.NET 7.0 is done. It is going to be released in a few days. We may consider servicing this later if proven it is a blocker to important scenarios. Considering the workaround is trivial and it is not a regression, this will be difficult to meet the servicing bar. |
Just encountered the same problem; such a shame that the fix didn't make it to 7.0...
What is the workaround, please? |
In the issue description, it mentioned the following
|
Description
With #67258 the binding of immutable types is working but with nested types seams not to work.
Reproduction Steps
In the above case the following exception will be thrown:
If the
Nested
property is declared withinit
modifier like bellow it will work.Expected behavior
No exception.
Actual behavior
Throws
InvalidOperationException
.Regression?
No response
Known Workarounds
Declare the
Nested
property withinit
modifier.Configuration
.NET 7 RC2
Other information
No response
The text was updated successfully, but these errors were encountered: