2

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.

0

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Add the Latest version of Swashbuckle.AspNetCore package from NuGet Package Manager then it will work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.