user10489212
user10489212

Reputation:

Why Swashbuckle.aspnet.core.swagger not being recognized

I've installed though nuget package manager the Swashbuckle.AspNetCore.Swagger and had included the using Swashbuckle.AspNetCore.Swagger on the top, but I get error on the Info{ Title} methods. Can anyone please suggest how to solve this issue.

 services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info { Title = "My DAB API", Version = "V3.2.2" });
            }); 

Upvotes: 13

Views: 15321

Answers (7)

Praveen Kumar
Praveen Kumar

Reputation: 1

while upgrading project to .net core 5.0 or 6.0, SwaggerDoc does have the SwaggerDoc("v1", info), instead of use SwaggerDoc("v1", new OpenApiInfo());

Upvotes: -1

Hamza Khanzada
Hamza Khanzada

Reputation: 1525

If you are using DotnetCore (>= 3.0) Make sure you are using Pre-Release (as of now Dec-19) of Swashbuckle.AspNetCore package which is -Version 5.0.0-rc4. I mistakenly installed the latest stable version 4.0.1 in which Microsoft.OpenApi.Models was missing.

See More On Microsoft

Upvotes: 7

Paul
Paul

Reputation: 69

Just install package Microsoft.OpenApi to resolve the issue

Upvotes: -1

vithal wadje
vithal wadje

Reputation: 197

I had same issue in ASP.NET Core 2.1 web api but I have resolved issue by first installing the lower version of package & upgrading it version by version

Swashbuckle.AspNetCore 2.1.0 and then after I have upgraded the package version by version until I got the same error but I haven't received same error again even upgrading till swashbuckle.AspNetCore 5.0.0-rc2 & its now working properly with following configuration

Use namespace as following because Info class is not more used in latest version of swagger instead of OpenApiInfo class used to describe about swagger metadata

using Microsoft.OpenApi.Models;

then use the following code in Startup.cs class under the ConfigureServices method

 services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new OpenApiInfo { Title = "www.compilemode.com", Version = "v1" });
        });

This is very strange resolution but this is the only work around I have found after spending lots of time.

Upvotes: 1

Jesus Rendon
Jesus Rendon

Reputation: 199

I find Solution.

For version 5

using Microsoft.OpenApi.Models;


services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});

Upvotes: 19

user10489212
user10489212

Reputation:

Well, I found the solution, Finally. I installed Swashbuckle.AspNetCore version 4.0.1. Obviously it wasn't working with the latest version which is 5.

Upvotes: 0

Khushali jasoliya
Khushali jasoliya

Reputation: 370

Uninstall package Swashbuckle.AspNetCore.Swagger and try this package Swashbuckle.AspNetCore.SwaggerGen.

Upvotes: 0

Related Questions