プロジェクトを.netコア2.2から3.0プレビュー7に移行したところです。その中でSwashbuckle.AspNetCore(v4.0.1)を使用しています。これは私のスタートアップクラスです。
public class Startup
{
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration["ConnectionStrings:ConnectionStringAzureSQL"]));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
services.AddApplicationInsightsTelemetry();
services.AddLocalization(options => options.ResourcesPath = @"Resources");
services.AddMemoryCache();
services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new List<CultureInfo>
{
new CultureInfo("en-US")
};
options.DefaultRequestCulture = new RequestCulture("en-US");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "GetAJobToday", Description = "GetAJobTodayAPIs" });
var xmlPath = AppDomain.CurrentDomain.BaseDirectory + @"PlatformAPI.xml";
c.IncludeXmlComments(xmlPath);
c.AddSecurityDefinition("Bearer",
new ApiKeyScheme
{
In = "header",
Description = "Please enter token into the field",
Name = "Authorization",
Type = "apiKey"
});
c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
{
{"Bearer", new string[] { }},
});
});
services.AddSingleton<ITelemetryInitializer, HttpContextItemsTelemetryInitializer>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseRouting();
app.UseMiddleware<ApiLoggingMiddleware>();
app.UseHttpsRedirection();
app.UseRequestLocalization(app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>().Value);
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapControllerRoute("default", "{controller=Auth}/{action=RequestVerificationCode}/{id?}");
});
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "GetAJobToday");
});
}
}
しかし、実行するとこの例外がスローされます。
AggregateException:一部のサービスを構築できません(サービス記述子の検証中にエラーが発生しました: 'ServiceType:Swashbuckle.AspNetCore.Swagger.ISwaggerProvider Lifetime:Transient ImplementationType:Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator':配列内の2つの要素を比較できませんでした。 )(サービス記述子の検証中のエラー 'ServiceType:Swashbuckle.AspNetCore.SwaggerGen.ISchemaRegistryFactory Lifetime:Transient ImplementationType:Swashbuckle.AspNetCore.SwaggerGen.SchemaRegistryFactory':配列内の2つの要素の比較に失敗しました。)
Swashbuckle.AspNetCoreおよびSwashbuckle.AspNetCore.Filtersをv 5.0.0-rc2にアップグレードすると、問題が解決しました。