我有一个ASP.NET Core Web应用程序,在其中使用以下命令使用swagger:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddSwaggerGen(c =>
    {
        c.OperationFilter<ExamplesOperationFilter>();
        c.OperationFilter<DescriptionOperationFilter>();
        c.SwaggerDoc("v1", new Info
        {
            Version = "v1",
            Title = "API",
            Description = "",
        });
        // Set the comments path for the Swagger JSON and UI.
        var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
        var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
        c.IncludeXmlComments(xmlPath);
    });
}


public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseSwagger();
    app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "API"); });
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseMvc();
}

当我导航到url/swagger时,出现以下错误:



我安装的nuget软件包是:

Swashbuckle.AspNetCore v3.0.0

Swashbuckle.AspNetCore.Examples v2.9.0

最佳答案

卸载程序包

Swashbuckle.AspNetCore.Examples

应该解决这个问题。新软件包是(尚未尝试过)-
Swashbuckle.AspNetCore.Filters

(更新)
新包装非常完美

关于c# - AspNetCore无法加载 'Swashbuckle.AspNetCore.SwaggerGen.SwaggerResponseAttribute'类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51842808/

10-12 23:34