admin管理员组

文章数量:1295066

I have an ASP.NET Core 9 Web API project that is created from the standard template in Visual Studio with no changes.

This is a fresh project that VS created, and I click run and get the following error

System.InvalidOperationException: 'Cannot resolve scoped service 'Microsoft.Extensions.Options.IOptionsSnapshot`1[Microsoft.AspNetCore.OpenApi.OpenApiOptions]' from root provider.'

What on earth is happening? Surely it should just run, otherwise what is the point in the template?

This is the program.cs file:

public static void Main(string[] args)
{
    var builder = WebApplication.CreateBuilder(args);

    // Add services to the container.

    builder.Services.AddControllers();
    // Learn more about configuring OpenAPI at 
    builder.Services.AddOpenApi();

    var app = builder.Build();

    // Configure the HTTP request pipeline.
    if (app.Environment.IsDevelopment())
    {
        app.MapOpenApi();
    }

    app.UseHttpsRedirection();

    app.UseAuthorization();

    app.MapControllers();

    app.Run();
}

If I create a new 8 WebApi project it works fine.

本文标签: