Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to find Bind() on OptionsBuilder

I have a class library that was written in .NET 5 and used the Microsoft.AspNetCore package, which is now deprecated. After upgrading my library to .NET 7 I'm getting this error:

'OptionsBuilder<AamSettings>' does not contain a definition for 'Bind' and no accessible extension method 'Bind' accepting a first argument of type 'OptionsBuilder<AamSettings>' could be found (are you missing a using directive or an assembly reference?)

If I look at the OptionsBuilderExtensions docs I see an extension method for Bind listed as being part of the Microsoft.Extensions.DependencyInjection namespace. My library includes that NuGet package, and the file has a using Microsoft.Extensions.DependencyInjection line at the top of the file.

What am I missing in order to be able to call Bind?

public static IServiceCollection AddAamClient(this IServiceCollection services, AamClientRegistrationOptions options)
{
    services
        .AddOptions<AamSettings>()
        .Bind(options.Configuration.GetRequiredSection(options.ConfigurationSectionName))
like image 864
Gargoyle Avatar asked Sep 05 '25 03:09

Gargoyle


1 Answers

with a reference to Microsoft.Extensions.Options.ConfigurationExtensions you could use:

services
    .AddOptions<AamSettings>()
    .BindConfiguration(options.ConfigurationSectionName);
like image 87
gke Avatar answered Sep 07 '25 20:09

gke