-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Possible regression: ConfigurationBinder cannot bind private properties of base classes #71040
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsDescriptionIn recent main branch, I found seems ConfigurationBinder cannot bind private properties of base classes, but before that, it can (for example .net 3, 5, 6). Recent main branch (I add an test case to show result): [Fact]
public void CanBindPrivatePropertiesFromBaseClass()
{
ConfigurationBuilder configurationBuilder = new();
configurationBuilder.AddInMemoryCollection(new Dictionary<string, string>
{
{ "PrivateProperty", "a" }
});
IConfiguration config = configurationBuilder.Build();
var test = new ClassOverridingVirtualProperty();
config.Bind(test, b => b.BindNonPublicProperties = true);
Assert.Equal("a", test.ExposePrivatePropertyValue());
}
public class BaseClassWithVirtualProperty
{
private string? PrivateProperty { get; set; }
public string? ExposePrivatePropertyValue() => PrivateProperty;
}
public class ClassOverridingVirtualProperty : BaseClassWithVirtualProperty
{
}`
### Reproduction Steps
As above.
### Expected behavior
`ConfigurationBinder` may should be able to bind private properties of base classes.
### Actual behavior
`ConfigurationBinder` cannot bind private properties of base classes in recent main branch.
### Regression?
Yes, it did.
### Known Workarounds
_No response_
### Configuration
Found this from main branch with commit version: 2ce8130f4bf4b02393b95719edb0f9d5c6ee1776, at least.
### Other information
I raised [PR](https://github.com/dotnet/runtime/pull/71039) to try to fix that, meantime can handle virtual properties.
<table>
<tr>
<th align="left">Author:</th>
<td>lateapexearlyspeed</td>
</tr>
<tr>
<th align="left">Assignees:</th>
<td>-</td>
</tr>
<tr>
<th align="left">Labels:</th>
<td>
`area-Extensions-Configuration`
</td>
</tr>
<tr>
<th align="left">Milestone:</th>
<td>-</td>
</tr>
</table>
</details> |
cc @pedrobsaila. Looks like this might be a regression from #70592. |
@eerhardt Thanks. Yes I noticed that PR before I raise my PR to fix. In short, I turn to keep using loop to retrieve all layers of properties (as .net 3/5/6) to be able to get also private properties (I guess this is reason to loop before). Meantime take care virtual and non virtual ones (even if with same names). Please review, thanks! |
Hi @eerhardt, any chance to have a look at PR above ? :) |
Description
In recent main branch, I found seems ConfigurationBinder cannot bind private properties of base classes, but before that, it can (for example .net 3, 5, 6).
In .net 3, 5, 6:

Recent main branch (I add an test case to show result):

I raised PR to try to fix that, meantime can handle virtual properties.
Reproduction Steps
As above.
Expected behavior
ConfigurationBinder
may should be able to bind private properties of base classes.Actual behavior
ConfigurationBinder
cannot bind private properties of base classes in recent main branch.Regression?
Yes, it did.
Known Workarounds
No response
Configuration
Found this from main branch with commit version: 2ce8130, at least.
Other information
I raised PR to try to fix that, meantime can handle virtual properties.
The text was updated successfully, but these errors were encountered: