Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve parameter 'Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider apiDescriptionsProvider

We use swagger for explore api and one time we turned off razor.

And this led to problem with swagger

Original error:

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)
like image 354
SanŚ́́́́Ý́́́́Ś́́́́ Avatar asked Dec 22 '22 23:12

SanŚ́́́́Ý́́́́Ś́́́́


1 Answers

How the problem appeared: we used services.AddMvcCore instead services.AddMvc

How resolve: add registration of ApiExplorer

For example:

services.AddMvcCore()
    .AddJsonFormatters()
    .AddApiExplorer(); // this line is solution of problem
like image 62
SanŚ́́́́Ý́́́́Ś́́́́ Avatar answered Dec 31 '22 10:12

SanŚ́́́́Ý́́́́Ś́́́́