C# 无法解析参数';Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider apisdescriptionprovider

C# 无法解析参数';Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider apisdescriptionprovider,c#,asp.net-core,.net-core,swagger,C#,Asp.net Core,.net Core,Swagger,我们使用swagger来探索api,有一次我们关闭了razor 这导致了招摇过市的问题 原始错误: An unhandled exception occurred while processing the request. DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on typ

我们使用swagger来探索api,有一次我们关闭了razor

这导致了招摇过市的问题

原始错误:

An unhandled exception occurred while processing the request.
DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' 
  on type 'Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator' can be invoked with the available services and parameters:
Cannot resolve parameter 'Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider apiDescriptionsProvider' 
  of constructor 'Void .ctor(Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider, Swashbuckle.AspNetCore.SwaggerGen.ISchemaRegistryFactory, Microsoft.Extensions.Options.IOptions`1[Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions])'.
Cannot resolve parameter 'Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider apiDescriptionsProvider' 
of constructor 'Void .ctor(Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider, Swashbuckle.AspNetCore.SwaggerGen.ISchemaRegistryFactory, Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions)'.
Autofac.Core.Activators.Reflection.ReflectionActivator.GetValidConstructorBindings(IComponentContext context, IEnumerable<Parameter> parameters)
处理请求时发生未处理的异常。
DependencyResolutionException:找不到具有“Autofac.Core.Activators.Reflection.DefaultConstructorFinder”的构造函数
可以使用可用的服务和参数调用类型“swashback.AspNetCore.SwaggerGen.SwaggerGenerator”上的:
无法解析参数“Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider apiscriptionprovider”
构造函数的Void.ctor(Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider,swashback.AspNetCore.SwaggerGen.ISchemaRegistryFactory,Microsoft.Extensions.Options.IOOptions`1[Swashback.AspNetCore.SwaggerGen.SwaggerGeneratorOptions])。
无法解析参数“Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider apiscriptionprovider”
构造函数“Void.ctor(Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider,swashback.AspNetCore.SwaggerGen.ISchemaRegistryFactory,swashback.AspNetCore.SwaggerGen.SwaggerGeneratorOptions)”的。
Autofac.Core.Activators.Reflection.ReflectionActivator.GetValidConstructorBindings(IComponentContext上下文,IEnumerable参数)

问题是如何出现的:我们使用了
服务。AddMvcCore
而不是
服务。AddMvc

如何解决:添加ApiExplorer的注册

例如:

services.AddMvcCore()
.AddJsonFormatters()文件
.AddApiExplorer();//这条线是问题的解决方案
我使用了
AddMvc()
,它得到了解决

例如:

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);