【发布时间】:2019-01-21 09:25:29
【问题描述】:
我有 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 时,我收到以下错误:
失败:Microsoft.AspNetCore.Server.Kestrel[13] 连接 id “0HLG1T7PRT05H”,请求 id:一个未处理的异常被抛出 应用。 System.TypeLoadException:无法加载类型 'Swashbuckle.AspNetCore.SwaggerGen.SwaggerResponseAttribute' 来自 程序集'Swashbuckle.AspNetCore.SwaggerGen,版本=3.0.0.0, 文化=中性'.at Swashbuckle.AspNetCore.Examples.DescriptionOperationFilter.SetResponseModelDescriptions(操作 操作,ISchemaRegistry schemaRegistry,ApiDescription apiDescription) 在 Swashbuckle.AspNetCore.Examples.DescriptionOperationFilter.Apply(操作 操作,OperationFilterContext 上下文)在 Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateOperation(ApiDescription apiDescription, ISchemaRegistry schemaRegistry) 在 Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItem(IEnumerable
1 apiDescriptions, ISchemaRegistry schemaRegistry) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 源,Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItems(IEnumerable1 apiDescriptions,ISchemaRegistry schemaRegistry)在 Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(字符串 documentName、字符串主机、字符串 basePath、字符串 [] 方案)在 Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext) 在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 申请)
我安装的nuget包是:
Swashbuckle.AspNetCore v3.0.0
Swashbuckle.AspNetCore.Examples v2.9.0
【问题讨论】:
-
希望如此,它可能会有所帮助github.com/RSuter/NSwag/issues/855
标签: c# asp.net-core swagger