使用此错误添加c.DocumentFilter<XmlCommentsDocumentFilter>();
会破坏API服务
System.ObjectDisposedException: Cannot write to the response body, the
response has completed.
Object name: 'HttpResponseStream'.
我正在使用https://github.com/Microsoft/aspnet-api-versioning
services.AddSwaggerGen(c =>
{
var provider = services.BuildServiceProvider().GetRequiredService<IApiVersionDescriptionProvider>();
// This is the offending line of code
c.DocumentFilter<XmlCommentsDocumentFilter>();
foreach (var description in provider.ApiVersionDescriptions)
{
c.SwaggerDoc(
description.GroupName,
new Info()
{
Title = $"API {description.ApiVersion}",
Version = description.ApiVersion.ToString(),
Description = "Services for handling resource requests",
}
});
}
var filePath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "API.xml");
c.IncludeXmlComments(filePath);
});