简体   繁体   中英

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" });
            }); 

I find Solution.

For version 5

using Microsoft.OpenApi.Models;


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

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

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.

卸载包Swashbuckle.AspNetCore.Swagger并尝试这个包Swashbuckle.AspNetCore.SwaggerGen

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.

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());

只需安装软件包 Microsoft.OpenApi 即可解决问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM