-
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
Microsoft.Extensions.Configuration.ConfigurationBinder.BindProperty(PropertyInfo,object, IConfiguration, BinderOptions) – harmful call to PropertyInfo.GetValue(object) #52905
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @maryamariyan, @safern Issue DetailsDescriptionThe
Lines
are obviously some debris somebody forgotten to remove. The line Moreover, why to obtain any property value before asking if it can be passed to existing setter. 👎🏻 ConfigurationMicrosoft.Extensions.Configuration.Binder 5.0.0 on .NET 5.0 Areaarea-Extensions-Configuration
|
This is currently biting me, where I have a read-only property on one of my objects that can potentially throw an exception if called before some extra setup is executed. This forces me to modify the behavior of the property so it doesn't throw while the binding process is happening. example: public class BindingObject
{
public string BindThisString { get; set; }
public OtherObject ThisIsNotSetDuringBinding { get; set; }
// This will throw an exception during binding, because the get is called for no good reason
public string DerivedPropertyString => $"DerivedProperty={ThisIsNotSetDuringBinding .Id}"
} |
Reopening since the fix introduced a regression and will be reverted. |
Make sure that any fix for this in the future accounts for the scenario here: #63479 |
Previously, ConfigurationBinder would eagerly read properties it encountered and initialize/bind objects for them even when those reads/initializations could lead to thrown exceptions or unnecessary work. Now, we defer work until we determine that it will actually contribute to the final binding result. Fix dotnet#52905 Fix dotnet#65710
Description
The
ConfigurationBinder.BindProperty
seems to beLines
object propertyValue = property.GetValue(instance);
,are obviously some debris somebody forgotten to remove. The line
object propertyValue = property.GetValue(instance);
can call to properties with not setter – like static properties – forcing them to execute.Moreover, why to obtain any property value before asking if it can be passed to existing setter. 👎🏻
Configuration
Microsoft.Extensions.Configuration.Binder 5.0.0 on .NET 5.0
Area
area-Extensions-Configuration
The text was updated successfully, but these errors were encountered: