An error occurred while starting the application.
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’: No constructor for type ‘Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’ can be instantiated using services from the service container and default values.) (Error while validating the service descriptor ‘ServiceType: Microsoft.Extensions.ApiDescriptions.IDocumentProvider Lifetime: Singleton ImplementationType: Microsoft.Extensions.ApiDescriptions.DocumentProvider’: No constructor for type ‘Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’ can be instantiated using services from the service container and default values.) (Error while validating the service descriptor ‘ServiceType: Swashbuckle.AspNetCore.Swagger.ISwaggerProvider Lifetime: Transient ImplementationType: Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’: No constructor for type ‘Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’ can be instantiated using services from the service container and default values.)
Microsoft.Extensions.DependencyInjection.ServiceProvider…ctor(IEnumerable serviceDescriptors, ServiceProviderOptions options)
InvalidOperationException: Error while validating the service descriptor ‘ServiceType: Swashbuckle.AspNetCore.Swagger.ISwaggerProvider Lifetime: Transient ImplementationType: Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’: No constructor for type ‘Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’ can be instantiated using services from the service container and default values.
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.ValidateService(ServiceDescriptor descriptor)
InvalidOperationException: Error while validating the service descriptor ‘ServiceType: Microsoft.Extensions.ApiDescriptions.IDocumentProvider Lifetime: Singleton ImplementationType: Microsoft.Extensions.ApiDescriptions.DocumentProvider’: No constructor for type ‘Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’ can be instantiated using services from the service container and default values.
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.ValidateService(ServiceDescriptor descriptor)
InvalidOperationException: Error while validating the service descriptor ‘ServiceType: Swashbuckle.AspNetCore.Swagger.ISwaggerProvider Lifetime: Transient ImplementationType: Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’: No constructor for type ‘Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’ can be instantiated using services from the service container and default values.
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.ValidateService(ServiceDescriptor descriptor)
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’: No constructor for type ‘Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’ can be instantiated using services from the service container and default values.) (Error while validating the service descriptor ‘ServiceType: Microsoft.Extensions.ApiDescriptions.IDocumentProvider Lifetime: Singleton ImplementationType: Microsoft.Extensions.ApiDescriptions.DocumentProvider’: No constructor for type ‘Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’ can be instantiated using services from the service container and default values.) (Error while validating the service descriptor ‘ServiceType: Swashbuckle.AspNetCore.Swagger.ISwaggerProvider Lifetime: Transient ImplementationType: Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’: No constructor for type ‘Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’ can be instantiated using services from the service container and default values.)
Microsoft.Extensions.DependencyInjection.ServiceProvider…ctor(IEnumerable serviceDescriptors, ServiceProviderOptions options)
Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory.CreateServiceProvider(IServiceCollection containerBuilder)
Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter.CreateServiceProvider(object containerBuilder)
Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
Microsoft.Extensions.Hosting.HostBuilder.Build()
Swagger.Program.Main(string[] args) in Program.cs
1.以.net3.0为基础环境,安装的swagger版本须为5.0.0.0-rc4
2.在startup中进行如下配置
引用OpenAI,并注册、启用
记得检查下这里是否为,否则就会犯和我一样的错误。
文章来源:https://www.toymoban.com/news/detail-693205.html
我的报错的原因是因为使用的模板是COREWEB应用,应当选择CoreWebAPI
文章来源地址https://www.toymoban.com/news/detail-693205.html
到了这里,关于Swagger配置报错的原因的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!