'System.InvalidOperationException error reason?

I am using BigBlueButtonAPI.NET Package in .Net6.

in my appsetting I declared these variables:

"BigBlueButtonAPISettings": {
"ServerAPIUrl": "https://myserver.com/bigbluebutton/api/",
"SharedSecret": "my shared secret here"
}

in my program.cs I wrote these codes:

builder.Services.Configure<BigBlueButtonAPISettings> 
(builder.Configuration.GetSection("BigBlueButtonAPISettings"));
builder.Services.AddScoped<BigBlueButtonAPIClient>(provider =>
  {
    var settings = provider.GetRequiredService<IOptions<BigBlueButtonAPISettings>>().Value;
    var factory = provider.GetRequiredService<IHttpClientFactory>();
    return new BigBlueButtonAPIClient(settings, factory.CreateClient());
  });

When I want to call an API inside my application, in program.cs I see this error:

enter image description here



Solution 1:[1]

Here is the answer. maybe it would be helpful for others too. I added builder.Services.AddHttpClient(); before the codes:

builder.Services.AddHttpClient();

builder.Services.Configure<BigBlueButtonAPISettings> 
(builder.Configuration.GetSection("BigBlueButtonAPISettings"));
builder.Services.AddScoped<BigBlueButtonAPIClient>(provider =>
{
var settings =provider.GetRequiredService<IOptions<BigBlueButtonAPISettings>>().Value;
var factory = provider.GetRequiredService<IHttpClientFactory>();
return new BigBlueButtonAPIClient(settings, 
factory.CreateClient());
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Masoud