AddSwaggerGen : not accessible

192 Views Asked by At

I am trying to create an ASP.NET Core 7 Web API, and I run into this error:

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

from line 8 and I also get the error

'WebApplication' does not contain a definition for 'UseSwagger' and no accessible extension method 'UseSwagger' accepting a first argument of type 'WebApplication' could be found (are you missing a using directive or any assembly reference

from line 15.

Here's my code

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllers();

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

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

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

I also run into other errors wherever swagger is being used. it's an ASP.NET Core Web API with use controllers and enable OpenAPI support both turned on in my Visual Studio Community edition, any help would be much appreciated

0

There are 0 best solutions below