-
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 swallows the conversion exception #73915
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsDescriptionConfiguration binding still swallows the conversion exception (#36502 is still reproducible with Reproduction Stepspublic enum Ingredients {
A,
B
}
public class MyModel{
public Ingredients[] {get;set;}
} Starting the app with Expected behaviorException should be thrown when calling Actual behaviorapplication starts with Regression?No response Known WorkaroundsNo response Configuration
Other informationNo response
|
Looks there are some places in the ConfigurationBinder.cs which we swallow the exception. We may consider using runtime/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs Line 614 in 8be2105
runtime/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs Line 647 in 8be2105
runtime/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs Line 696 in 8be2105
runtime/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs Line 755 in 8be2105
We may consider the fix in the future releases. |
I just wasted 4 hours debugging until I arrived at this issue. I agree with @jvmlet that this should be a blocker and at the very minimum a binding option should be provided to fail on children error. |
@tarekgh , would you please prioritize it ? |
@jvmlet I marked with the next release milestone. Are you interested in submitting a PR for it? |
I'm happy to look at this as I vaguely remember adding |
The comments for /// <summary>
/// When false (the default), no exceptions are thrown when a configuration key is found for which the
/// provided model object does not have an appropriate property which matches the key's name.
/// When true, an <see cref="System.InvalidOperationException"/> is thrown with a description
/// of the missing properties.
/// </summary> So, technically, in this case, the key exists, and the config exists, so 🙈 Of course, that config option implies that an error should be thrown, not just on missing properties in config, but also invalid properties in config. By making Maybe we need another property named What do you think? Would this require another API Proposal? |
I don't think we need to complicate the options by adding one more property like that. We can use |
This is already done by the PR #77708 |
Description
Configuration binding still swallows the conversion exception (#36502 ,#36129 and #36015 are still reproducible with
6.0.0
, )Reproduction Steps
Starting the app with
myapp.exe --MyModel:Ingredients:0 A --MyModel:Ingredients:1 C
starts up withIngredients == [A]
Expected behavior
Exception should be thrown when calling
iConfiguration.GetSection("MyModel").Bind(new MyModel(),opts => opts.ErrorOnUnknownConfiguration = true))
Actual behavior
application starts with
Ingredients == [A]
Regression?
No response
Known Workarounds
No response
Configuration
net5.0
,<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
Other information
(
runtime/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs
Line 543 in c0dabb5
The text was updated successfully, but these errors were encountered: