-
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 throws on an abstract member rather than binding to existing value #92137
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsDescriptionWhen encountering an abstract type in an object graph the configuration generator tries to create it and throws. This is inconsistent with the runtime binder, which will use an existing instance. I wonder if we should warn on this or not. Definitely if the abstract type is the root and we're generating Reproduction StepsRun attached repro project: Also shown here: https://gist.github.com/ericstj/121fe52f9a1b5115b246c08605c685c0 To see expected behavior remove
Note that the runtime binder didn't rely on seeing the derived type and creating a new one -- this is apparent by seeing that the object is the same before and after then bind. Expected behaviorRepro runs successfully and sets the members on the existing instance of the derived type. Not creating a new instance nor throwing. Actual behaviorWarning emitted by the source generator:
And exception thrown at runtime:
Regression?No response Known WorkaroundsDisable generator. ConfigurationNo response Other informationNo response
|
Currently unsure how general this issue is... we should test not just |
Yeah, and compare to what the runtime binder does here. For example if it prefers an existing instance over creating one vs if it prefers creating one if it can. I don't recall what the precedence is. |
Description
When encountering an abstract type in an object graph the configuration generator tries to create it and throws.
This is inconsistent with the runtime binder, which will use an existing instance.
I wonder if we should warn on this or not. Definitely if the abstract type is the root and we're generating
Get
calls that's a problem. Anywhere else it could be supported if the member is already initialized - since we won't need to create one in the binder.Reproduction Steps
Run attached repro project:
bindAbstract.zip
Also shown here: https://gist.github.com/ericstj/121fe52f9a1b5115b246c08605c685c0
To see expected behavior remove
EnableConfigurationBindingGenerator
. You'll see the outputNote that the runtime binder didn't rely on seeing the derived type and creating a new one -- this is apparent by seeing that the object is the same before and after then bind.
Expected behavior
Repro runs successfully and sets the members on the existing instance of the derived type. Not creating a new instance nor throwing.
Actual behavior
Warning emitted by the source generator:
And exception thrown at runtime:
Regression?
No response
Known Workarounds
Disable generator.
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: