Configuration binding does not throw when it should #110147
Labels
area-Extensions-Configuration
in-pr
There is an active PR which will close this issue when it is merged
regression-from-last-release
Milestone
Description
Binding a configuration using Microsoft.Extensions.Configuration.Binder 9.0.0 with
ErrorOnUnknownConfiguration
set totrue
should throw anInvalidOperationException
as documented in .NET 8 breaking changes - ConfigurationBinder throws for mismatched value.Unfortunately, it doesn't throw that exception and binding succeeds when it should fail.
Reproduction Steps
BindConfiguration.csproj
Program.cs
Expected behavior
Running
dotnet run
should printActual behavior
Running
dotnet run
printsRegression?
This is a regression from
Microsoft.Extensions.Configuration.Binder
version 8.0.2 where it properly throws anInvalidOperationException
.Note that the regression was introduced between version 9.0.0-preview.1.24080.9 (1d1bf92) where it still throws as expected and version 9.0.0-preview.2.24128.5 (8e5e748) where it doesn't throw anymore.
Known Workarounds
Since it's a regression the workaround is to stay on☹️
Microsoft.Extensions.Configuration.Binder
version 8.0.2.Configuration
Other information
Note that setting
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
in the project to enable the binder source generator never works as expected (i.e. never throws), even with version 8.0.2. So a separate issue should probably be opened about it.Also it's "funny" that this issue is basically the inverse of #98231 where it throws even though
ErrorOnUnknownConfiguration
is set to false.Finally, I still stand by my point that repurposing the
ErrorOnUnknownConfiguration
property to control whether an exception must be thrown when a conversion fails was not a good idea and that it's never too late to introduce a new property to the options to control the exception behaviour separately from unknown/missing configuration keys.The text was updated successfully, but these errors were encountered: