diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs b/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs
index 2e00d25656843..ef54ebcedf0e6 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs
+++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs
@@ -30,7 +30,7 @@ public static class ConfigurationBinder
/// The new instance of T if successful, default(T) otherwise.
[RequiresUnreferencedCode(TrimmingWarningMessage)]
public static T? Get<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration)
- => configuration.Get(null);
+ => configuration.Get(_ => { });
///
/// Attempts to bind the configuration instance to a new instance of type T.
@@ -42,12 +42,16 @@ public static class ConfigurationBinder
/// Configures the binder options.
/// The new instance of T if successful, default(T) otherwise.
[RequiresUnreferencedCode(TrimmingWarningMessage)]
- public static T? Get<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration, Action? configureOptions)
+ public static T? Get<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IConfiguration configuration, Action configureOptions)
{
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}
+ if (configureOptions is null)
+ {
+ throw new ArgumentNullException(nameof(configureOptions));
+ }
object? result = configuration.Get(typeof(T), configureOptions);
if (result == null)
@@ -67,7 +71,7 @@ public static class ConfigurationBinder
/// The new instance if successful, null otherwise.
[RequiresUnreferencedCode(TrimmingWarningMessage)]
public static object? Get(this IConfiguration configuration, Type type)
- => configuration.Get(type, null);
+ => configuration.Get(type, _ => { });
///
/// Attempts to bind the configuration instance to a new instance of type T.
@@ -83,7 +87,7 @@ public static class ConfigurationBinder
this IConfiguration configuration,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Type type,
- Action? configureOptions)
+ Action configureOptions)
{
if (configuration == null)
{
@@ -91,7 +95,7 @@ public static class ConfigurationBinder
}
var options = new BinderOptions();
- configureOptions?.Invoke(options);
+ configureOptions(options);
return BindInstance(type, instance: null, config: configuration, options: options);
}