gpt4 book ai didi

c# - AspNetCore 无法加载类型 'Swashbuckle.AspNetCore.SwaggerGen.SwaggerResponseAttribute'

转载 作者:太空狗 更新时间:2023-10-30 00:37:24 38 4
gpt4 key购买 nike

我有 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 时,出现以下错误:

fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HLG1T7PRT05H", Request id: An unhandled exception was thrown by the application. System.TypeLoadException: Could not load type 'Swashbuckle.AspNetCore.SwaggerGen.SwaggerResponseAttribute' from assembly 'Swashbuckle.AspNetCore.SwaggerGen, Version=3.0.0.0, Culture=neutral'.at Swashbuckle.AspNetCore.Examples.DescriptionOperationFilter.SetResponseModelDescriptions(Operation operation, ISchemaRegistry schemaRegistry, ApiDescription apiDescription) at Swashbuckle.AspNetCore.Examples.DescriptionOperationFilter.Apply(Operation operation, OperationFilterContext context) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateOperation(ApiDescription apiDescription, ISchemaRegistry schemaRegistry) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItem(IEnumerable1
apiDescriptions, ISchemaRegistry schemaRegistry) at
System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable
1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) at
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItems(IEnumerable
1 apiDescriptions, ISchemaRegistry schemaRegistry) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath, String[] schemes) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

我安装的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/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com