-
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
ConfigurationBinder source generator generates non-compilable code with new property and internal setter #101267
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration |
Ran some tests for comparison:
If I remove the So the bug here happens to be when a derived type hides a property of a base and changes visibility. I recall some other issue where we explicitly considered "new" members and what the behavior should be - if we allow those to have precedence when binding or not. I wonder what our reflection binder does here - I think it would bind against the internal thing without any problem. Yep that's the case: var cd = new CertificateDescription();
builder.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
{
["Certificate"] = "MyCertificate"
});
builder.Configuration.Bind(cd);
Console.WriteLine(cd.Certificate); outputs:
|
@eiriktsarpalis - it looks like you addressed a similar issue in #87383 I think the bug in Configuration here is that its overwriting an existing property with one from a more base type: Line 673 in b621129
A minimal fix here would be to just add if (properties?.ContainsKey(propertyName))
continue; |
dotnet build
on the following projects results in the generated source from the Configuration.Binder source generator to not compile.Library
App
Expected result
I expect the code to compile. It may emit warnings if it was unable to bind properties correctly.
Actual result
Generated code
cc @ericstj @tarekgh @eiriktsarpalis
The text was updated successfully, but these errors were encountered: