Skip to content

Honour ErrorOnUnknownConfiguration on value conversion fail - #131933

Draft
rosebyte wants to merge 1 commit into
dotnet:mainfrom
rosebyte:rosebyte-fix-binder-error-on-unknown-configuratio
Draft

Honour ErrorOnUnknownConfiguration on value conversion fail#131933
rosebyte wants to merge 1 commit into
dotnet:mainfrom
rosebyte:rosebyte-fix-binder-error-on-unknown-configuratio

Conversation

@rosebyte

@rosebyte rosebyte commented Aug 6, 2026

Copy link
Copy Markdown
Member

Fixes #98231

Problem

BinderOptions.ErrorOnUnknownConfiguration is documented as controlling whether the binder
throws "when converting a value", but it was only honoured on some of the paths that can fail:

Failure Flag honoured?
Unknown configuration key Yes
Leaf value with no TypeConverter at all Yes
Collection item that fails to convert Yes
Leaf value whose TypeConverter throws No, always threw

So a single malformed value in an otherwise valid configuration source would tear down binding
even for callers that had deliberately left the flag at its default:

// appsettings.json: { "Timeout": "not-a-number" }
var options = config.Get<MyOptions>();   // threw InvalidOperationException

This is inconsistent both with the documented contract on the property and with the sibling
"no converter" case a few lines away in the same method, which already returned quietly.

Fix

Gate the rethrow on the flag, in both the reflection binder and the source generator.

Reflection binder

BindInstance no longer rethrows the conversion error unconditionally; it returns and leaves
the binding point untouched, so the member keeps whatever value it already had.

Source generator

The emitted ParseX(value, path) helpers become TryParseX(value, path, errorOnFailedBinding, out result):

public static bool TryParseInt(string value, string? path, bool errorOnFailedBinding, out int result)
{
    try
    {
        result = int.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
        return true;
    }
    catch when (!errorOnFailedBinding)
    {
        result = default;
        return false;
    }
    catch (Exception exception)
    {
        throw new InvalidOperationException($"Failed to convert configuration value '{value ?? "null"}' at '{path}' to type '{typeof(int)}'.", exception);
    }
}

Call sites pass binderOptions?.ErrorOnUnknownConfiguration is true, except for two cases that
must always report the failure:

  • GetValueCore, since GetValue<T> has no BinderOptions overload.
  • Constructor parameters with no declared default, which are unsatisfiable either way. These keep
    throwing the accurate Failed to convert configuration value ... rather than degrading to
    ... has no matching config.

A try/catch at each call site was considered instead, but it would also have swallowed nested
binding errors in the dictionary case; a Func<>-based helper would have allocated.

Behaviour change

This is a breaking change and will need a breaking-change doc.

Scenario Before After
Bind / Get<T> with an unconvertible scalar, default options throws member keeps its existing value
GetSection("x").Get<int>() with a bad value throws default(int)
Same, with ErrorOnUnknownConfiguration = true throws throws (unchanged)
GetValue<T> with a bad value throws throws (unchanged)
Required constructor parameter with a bad value throws throws (unchanged)
Constructor parameter with a declared default and a bad value throws falls back to the default

The Get/Bind versus GetValue asymmetry is deliberate and follows the design agreed in the
issue, but it is user-visible.

Also in this change

  • Fixes a latent generator bug: a primitive section with an empty value used to fall through
    GetCore to throw new NotSupportedException("Unable to bind to type ...: generator did not detect the type as input."). It now returns null, matching the reflection binder.
  • Fixes a hard-coded path separator in GeneratorTests.Helpers.cs that stopped
    /p:UpdateBaselines=true working on non-Windows hosts.
  • Un-gates two CollectionsBindingWithErrorOnUnknownConfiguration tests that were restricted to
    the reflection binder; they now pass under source generation too.

Testing

  • 4 existing tests that asserted the old unconditional throw now opt in with
    ErrorOnUnknownConfiguration = true.
  • New regression tests cover both flag states, the GetValue carve-out, and constructor
    parameters with and without declared defaults. All run in both binder modes.
  • 111 of the 120 generator baselines regenerated (netcoreapp and net462, Version0 and
    Version1). Some net462 Version0 files additionally pick up unrelated drift corrections
    that had accumulated on main.
Microsoft.Extensions.Configuration.Binder.Tests                    356 passed, 0 failed
Microsoft.Extensions.Configuration.Binder.SourceGeneration.Tests   433 passed, 0 failed, 26 skipped

…otnet#131354)

# Honour ErrorOnUnknownConfiguration on value conversion fail

Fixes dotnet#98231

## Problem

`BinderOptions.ErrorOnUnknownConfiguration` is documented as controlling whether the binder
throws "when converting a value", but it was only honoured on some of the paths that can fail:

| Failure | Flag honoured? |
|---|---|
| Unknown configuration key | Yes |
| Leaf value with no `TypeConverter` at all | Yes |
| Collection item that fails to convert | Yes |
| **Leaf value whose `TypeConverter` throws** | **No, always threw** |

So a single malformed value in an otherwise valid configuration source would tear down binding
even for callers that had deliberately left the flag at its default:

```csharp
// appsettings.json: { "Timeout": "not-a-number" }
var options = config.Get<MyOptions>();   // threw InvalidOperationException
```

This is inconsistent both with the documented contract on the property and with the sibling
"no converter" case a few lines away in the same method, which already returned quietly.

## Fix

Gate the rethrow on the flag, in both the reflection binder and the source generator.

### Reflection binder

`BindInstance` no longer rethrows the conversion error unconditionally; it returns and leaves
the binding point untouched, so the member keeps whatever value it already had.

### Source generator

The emitted `ParseX(value, path)` helpers become `TryParseX(value, path, errorOnFailedBinding, out result)`:

```csharp
public static bool TryParseInt(string value, string? path, bool errorOnFailedBinding, out int result)
{
    try
    {
        result = int.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
        return true;
    }
    catch when (!errorOnFailedBinding)
    {
        result = default;
        return false;
    }
    catch (Exception exception)
    {
        throw new InvalidOperationException($"Failed to convert configuration value '{value ?? "null"}' at '{path}' to type '{typeof(int)}'.", exception);
    }
}
```

Call sites pass `binderOptions?.ErrorOnUnknownConfiguration is true`, except for two cases that
must always report the failure:

- `GetValueCore`, since `GetValue<T>` has no `BinderOptions` overload.
- Constructor parameters with no declared default, which are unsatisfiable either way. These keep
  throwing the accurate `Failed to convert configuration value ...` rather than degrading to
  `... has no matching config`.

A try/catch at each call site was considered instead, but it would also have swallowed nested
binding errors in the dictionary case; a `Func<>`-based helper would have allocated.

## Behaviour change

This is a breaking change and will need a breaking-change doc.

| Scenario | Before | After |
|---|---|---|
| `Bind` / `Get<T>` with an unconvertible scalar, default options | throws | member keeps its existing value |
| `GetSection("x").Get<int>()` with a bad value | throws | `default(int)` |
| Same, with `ErrorOnUnknownConfiguration = true` | throws | throws (unchanged) |
| `GetValue<T>` with a bad value | throws | throws (unchanged) |
| Required constructor parameter with a bad value | throws | throws (unchanged) |
| Constructor parameter with a declared default and a bad value | throws | falls back to the default |

The `Get`/`Bind` versus `GetValue` asymmetry is deliberate and follows the design agreed in the
issue, but it is user-visible.

## Also in this change

- Fixes a latent generator bug: a primitive section with an empty value used to fall through
  `GetCore` to `throw new NotSupportedException("Unable to bind to type ...: generator did not
  detect the type as input.")`. It now returns `null`, matching the reflection binder.
- Fixes a hard-coded path separator in `GeneratorTests.Helpers.cs` that stopped
  `/p:UpdateBaselines=true` working on non-Windows hosts.
- Un-gates two `CollectionsBindingWithErrorOnUnknownConfiguration` tests that were restricted to
  the reflection binder; they now pass under source generation too.

## Testing

- 4 existing tests that asserted the old unconditional throw now opt in with
  `ErrorOnUnknownConfiguration = true`.
- New regression tests cover both flag states, the `GetValue` carve-out, and constructor
  parameters with and without declared defaults. All run in both binder modes.
- 111 of the 120 generator baselines regenerated (`netcoreapp` and `net462`, `Version0` and
  `Version1`). Some `net462` `Version0` files additionally pick up unrelated drift corrections
  that had accumulated on `main`.

```
Microsoft.Extensions.Configuration.Binder.Tests                    356 passed, 0 failed
Microsoft.Extensions.Configuration.Binder.SourceGeneration.Tests   433 passed, 0 failed, 26 skipped
```
Copilot AI review requested due to automatic review settings August 6, 2026 11:43
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@rosebyte rosebyte changed the title [wasm][R2R] Request flat layout for composite image on WebAssembly (#131354) Honour ErrorOnUnknownConfiguration on value conversion fail Aug 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Microsoft.Extensions.Configuration.Binder to consistently honor BinderOptions.ErrorOnUnknownConfiguration when value conversion fails, including when a TypeConverter exists but throws, and aligns the source-generated binder behavior with the reflection binder.

Changes:

  • Reflection binder: suppresses conversion exceptions by default and preserves existing member values unless ErrorOnUnknownConfiguration (or a required-parameter carve-out) forces throwing.
  • Source generator: replaces ParseX helpers with TryParseX(..., errorOnFailedBinding, out result) and updates call sites/baselines to gate conversion failures on the binder option (with explicit always-throw carve-outs).
  • Tests/baselines: add coverage for the new behavior and update generator baselines; fix baseline update path handling for non-Windows hosts.

Reviewed changes

Copilot reviewed 118 out of 118 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs Gates leaf conversion failures on ErrorOnUnknownConfiguration (and a required-parameter “must throw” path).
src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Specs/TypeIndex.cs Renames/retargets parse helper naming to TryParse* for generated code.
src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/Helpers.cs Adds generator identifiers/expressions to plumb errorOnFailedBinding and result through emitted helpers.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.cs Updates existing tests to opt into throwing and adds new tests for default “suppress conversion failures” behavior + carve-outs.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.TestClasses.cs Adds new test model and ungates two tests to run under source-gen mode as well.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Helpers.cs Fixes baseline-update path composition to be cross-platform.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Version1/UnsupportedTypes.generated.txt Baseline update for TryParse* + option-gated conversion handling.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Version0/EmptyConfigType.generated.txt Baseline update for type name qualification / helper signatures.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_name.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_name_BinderOptions.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_BinderOptions.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/BindConfigurationWithConfigureActions.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/BindConfiguration.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/Bind_T.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/Bind_T_BinderOptions.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version0/BindConfigurationWithConfigureActions.generated.txt Baseline update for TryParse* call pattern + qualification drift.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version0/BindConfiguration.generated.txt Baseline update for TryParse* call pattern + qualification drift.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/GetValue.generated.txt Baseline update: GetValueCore uses TryParse* with always-throw behavior.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/GetValue_TypeOf_Key.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/GetValue_TypeOf_Key_DefaultValue.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/GetValue_T_Key.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/GetValue_T_Key_DefaultValue.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get_TypeOf.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get_TypeOf_BinderOptions.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get_PrimitivesOnly.generated.txt Baseline update: primitive leaf binding returns null on empty/unconvertible values unless opted in.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Key_Instance.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Instance.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Instance_BinderOptions.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version0/GetValue.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version0/GetValue_TypeOf_Key.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version0/GetValue_TypeOf_Key_DefaultValue.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version0/GetValue_T_Key.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version0/GetValue_T_Key_DefaultValue.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version0/Get_TypeOf.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version0/Get_TypeOf_BinderOptions.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version0/Get_PrimitivesOnly.generated.txt Baseline update: primitive leaf binding returns null on empty/unconvertible values unless opted in.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Version1/UnsupportedTypes.generated.txt Baseline update for TryParse* + option-gated conversion handling.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Version0/EmptyConfigType.generated.txt Baseline update: emits TryGetConfigurationValue helper + qualification drift.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_name.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_name_BinderOptions.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_BinderOptions.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/BindConfigurationWithConfigureActions.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/BindConfiguration.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/Bind_T.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/Bind_T_BinderOptions.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/GetValue.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/GetValue_TypeOf_Key.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/GetValue_TypeOf_Key_DefaultValue.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/GetValue_T_Key.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/GetValue_T_Key_DefaultValue.generated.txt Baseline update: TryParse* always-throw for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get_TypeOf.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get_TypeOf_BinderOptions.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get_PrimitivesOnly.generated.txt Baseline update: primitive leaf binding returns null on empty/unconvertible values unless opted in.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Key_Instance.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Instance.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Instance_BinderOptions.generated.txt Baseline update for TryParse* call pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version0/GetValue.generated.txt Baseline update: introduces TryGetConfigurationValue and TryParse* helpers for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version0/GetValue_TypeOf_Key.generated.txt Baseline update: introduces TryGetConfigurationValue and TryParse* helpers for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version0/GetValue_TypeOf_Key_DefaultValue.generated.txt Baseline update: introduces TryGetConfigurationValue and TryParse* helpers for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version0/GetValue_T_Key.generated.txt Baseline update: introduces TryGetConfigurationValue and TryParse* helpers for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version0/GetValue_T_Key_DefaultValue.generated.txt Baseline update: introduces TryGetConfigurationValue and TryParse* helpers for GetValue*.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version0/Get_TypeOf.generated.txt Baseline update: switches to TryGetConfigurationValue + TryParse* pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version0/Get_TypeOf_BinderOptions.generated.txt Baseline update: switches to TryGetConfigurationValue + TryParse* pattern.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version0/Get_PrimitivesOnly.generated.txt Baseline update: primitive leaf binding uses TryGetConfigurationValue and returns null when unconvertible unless opted in.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version0/Bind_ParseTypeFromMethodParam.generated.txt Baseline update: method names and helper inclusion drift (TryGetConfigurationValue emission).

Comment on lines +365 to +373
// A conversion failure is only reported when the caller opted in, matching how the binder treats
// a leaf value it has no converter for at all. Otherwise the binding point is left alone so the
// member keeps whatever value it already had.
if (options.ErrorOnUnknownConfiguration || errorOnFailedBinding)
{
throw error;
}

return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configuration binding ignores ErrorOnUnknownConfiguration and throws

2 participants