[Swagger]Unable to resolve service for type 'Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider' while attempting to activate

详细错误如下

===================

System.AggregateException:“Some services are not able to be constructed (Error while validating the service descriptor ‘ServiceType: Swashbuckle.AspNetCore.Swagger.ISwaggerProvider Lifetime: Transient ImplementationType: Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator‘: Unable to resolve service for type ‘Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider‘ while attempting to activate ‘Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator‘.) (Error while validating the service descriptor ‘ServiceType: Microsoft.Extensions.ApiDescriptions.IDocumentProvider Lifetime: Singleton ImplementationType: Microsoft.Extensions.ApiDescriptions.DocumentProvider‘: Unable to resolve service for type ‘Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider‘ while attempting to activate ‘Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator‘.)”

环境

===================

环境NetCore5.0

VS:2019

 

解决方案

==========================

参考:https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-5.0&tabs=visual-studio

需要在ConfigureServices添加 services.AddMvc();

技术图片

 

相关文章