我有 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, Version=3.0.0.0, Culture=neutral”中加载类型“Swashbuckle.AspNetCore.SwaggerGen.SwaggerResponseAttribute”。在 Swashbuckle.AspNetCore.Examples.DescriptionOperationFilter.SetResponseModelDescriptions( , ISchemaRegistry schemaRegistry, ApiDescription apiDescription) at Swashbuckle.AspNetCore.Examples.DescriptionOperationFilter.Apply(Operation operation, OperationFilterContext context) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateOperation(ApiDescription apiDescription, ISchemaRegistryCorenetschemaRegistry.Asp)1
apiDescriptions, ISchemaRegistry schemaRegistry) at
System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 个源,Func 2 keySelector, Func2 elementSelector,IEqualityComparer 1 comparer) at
我安装的nuget包是:
Swashbuckle.AspNetCore v3.0.0
Swashbuckle.AspNetCore.Examples v2.9.0
繁星淼淼
烙印99
波斯汪
相关分类