Reputation: 4571
I am trying to add Swagger to my ASP.Net Core Web API project, like this:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v0.1", new OpenApiInfo { Title = "My API", Version = "v0.1" });
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.UseHttpsRedirection();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v0.1/swagger.json", "My API V1");
});
app.UseRouting();
app.UseAuthorization();
...
}
but I am getting this error:
The type or namespace name 'OpenApiInfo' could not be found
I have installed Swashbuckle.AspNetCore v4.0.1, and my project is .Net Core 3.0.
Upvotes: 2
Views: 3060
Reputation: 743
Add the Latest version of Swashbuckle.AspNetCore package from NuGet Package Manager then it will work.
Upvotes: 0
Reputation: 13676
The reason it is not working is because the type OpenApiInfo
comes together with the latest version of Swashbuckle.AspNetCore
; open the nuget packages manager, tick the 'include prerelease' checkbox and update the package to version 5.0.0-rc3.
And then it should work.
Upvotes: 7