.net core 3.0 pre9 Swashbuckle.AspNetCore5.0 error
See original GitHub issueSystem.AggregateException
HResult=0x80131500
Message=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’: Failed to compare two elements in the array.) (Error while validating the service descriptor ‘ServiceType: Swashbuckle.AspNetCore.SwaggerGen.ISchemaRegistryFactory Lifetime: Transient ImplementationType: Swashbuckle.AspNetCore.SwaggerGen.SchemaRegistryFactory’: Failed to compare two elements in the array.)
Source=Microsoft.Extensions.DependencyInjection
StackTrace:
at Microsoft.Extensions.DependencyInjection.ServiceProvider…ctor(IEnumerable1 serviceDescriptors, ServiceProviderOptions options) at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options) at Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory.CreateServiceProvider(IServiceCollection containerBuilder) at Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter
1.CreateServiceProvider(Object containerBuilder)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at Paperlee.FOStock.WebAPI.Program.Main(String[] args) in G:\selfproj\FOStock\Paperlee.FOStock.WebAPI\Program.cs:line 17
内部异常 1: InvalidOperationException: Error while validating the service descriptor ‘ServiceType: Swashbuckle.AspNetCore.Swagger.ISwaggerProvider Lifetime: Transient ImplementationType: Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator’: Failed to compare two elements in the array.
内部异常 2: InvalidOperationException: Failed to compare two elements in the array.
内部异常 3: TypeLoadException: Could not load type ‘Microsoft.AspNetCore.Mvc.MvcJsonOptions’ from assembly ‘Microsoft.AspNetCore.Mvc.Formatters.Json, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60’.
startup.cs
public void ConfigureServices(IServiceCollection services) { services.AddControllers(options => { options.Filters.Add<ActionFilter>(); }); services.AddCors(options => { options.AddPolicy(“AllowAllOrigin”, builder => { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials(); }); }); services.AddSwaggerGen(options => { options.SwaggerDoc(“v1”, new Info { Version = “Version 1.0”, Title = “通用数据API”, Description = “Author:Lee” }); options.OperationFilter<OAuthHeaderParameter>(); SwaggerHelper.LoadXml(options, new string[] { “JQProject.FOStock.IApp.xml”, “JQProject.FOStock.WebAPI.xml” }, AppContext.BaseDirectory); }); //new StartupConfig().Init(services); }
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:11 (2 by maintainers)
Brubning thanks for the pointer… working great now. I have to change the signature to
services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "Put title here", Description = "DotNet Core Api 3 - with swagger" }); });
I am having the same issue, running .net core 3. everything is the latest version.