Exception 将项目从.net core 2.2迁移到3.0 preview-7后,招摇过市不起作用(而是引发异常)

Exception 将项目从.net core 2.2迁移到3.0 preview-7后,招摇过市不起作用(而是引发异常),exception,swagger,asp.net-core-webapi,swashbuckle,Exception,Swagger,Asp.net Core Webapi,Swashbuckle,我刚刚将我的项目从.NETCore2.2迁移到3.0Preview 7。我在其中使用了Swashback.AspNetCore(v4.0.1)。这是我的创业课 public class Startup { public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the contain

我刚刚将我的项目从.NETCore2.2迁移到3.0Preview 7。我在其中使用了Swashback.AspNetCore(v4.0.1)。这是我的创业课

public class Startup
    {
public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {

            services.AddDbContext<ApplicationDbContext>(options =>
                                                            options.UseSqlServer(
                                                            Configuration["ConnectionStrings:ConnectionStringAzureSQL"]));

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


            services.AddApplicationInsightsTelemetry();

            services.AddLocalization(options => options.ResourcesPath = @"Resources");

            services.AddMemoryCache();

            services.Configure<RequestLocalizationOptions>(options =>
            {
                var supportedCultures = new List<CultureInfo>
                    {
                        new CultureInfo("en-US")
                    };

                options.DefaultRequestCulture = new RequestCulture("en-US");
                options.SupportedCultures = supportedCultures;
                options.SupportedUICultures = supportedCultures;
            });

            services.AddSwaggerGen(c =>
            {

                c.SwaggerDoc("v1", new Info { Title = "GetAJobToday", Description = "GetAJobTodayAPIs" });

                var xmlPath = AppDomain.CurrentDomain.BaseDirectory + @"PlatformAPI.xml";
                c.IncludeXmlComments(xmlPath);

                c.AddSecurityDefinition("Bearer",
                new ApiKeyScheme
                {
                    In = "header",
                    Description = "Please enter token into the field",
                    Name = "Authorization",
                    Type = "apiKey"
                });

                c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
                {
                    {"Bearer", new string[] { }},
                });
            });

            services.AddSingleton<ITelemetryInitializer, HttpContextItemsTelemetryInitializer>();


        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseRouting();

            app.UseMiddleware<ApiLoggingMiddleware>();

            app.UseHttpsRedirection();

            app.UseRequestLocalization(app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>().Value);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapControllerRoute("default", "{controller=Auth}/{action=RequestVerificationCode}/{id?}");
            });

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "GetAJobToday");
            });
        }
    }
公共类启动
{
公共IConfiguration配置{get;}
//此方法由运行时调用。请使用此方法将服务添加到容器中。
public void配置服务(IServiceCollection服务)
{
services.AddDbContext(选项=>
options.UseSqlServer(
配置[“ConnectionString:ConnectionString-GazureSQL”]);
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
services.AddApplicationInsightsTelemetry();
services.AddLocalization(options=>options.ResourcesPath=@“Resources”);
services.AddMemoryCache();
配置(选项=>
{
var supportedCultures=新列表
{
新文化信息(“en-US”)
};
options.DefaultRequestCulture=新的RequestCulture(“en-US”);
options.SupportedCultures=SupportedCultures;
options.supportedCultures=supportedCultures;
});
services.AddSwaggerGen(c=>
{
c、 大摇大摆的文件(“v1”,新信息{Title=“getajobootoday”,Description=“getajobootodayapis”});
var xmlPath=AppDomain.CurrentDomain.BaseDirectory+@“PlatformAPI.xml”;
c、 includexmlcoments(xmlPath);
c、 AddSecurityDefinition(“承载人”,
新ApiKeyScheme
{
In=“header”,
Description=“请在字段中输入令牌”,
Name=“授权”,
Type=“apiKey”
});
c、 AddSecurityRequest(新字典)
{
{“Bearer”,新字符串[]{},
});
});
services.AddSingleton();
}
//此方法由运行时调用。请使用此方法配置HTTP请求管道。
公共无效配置(IApplicationBuilder应用程序,IHostingEnvironment环境)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
其他的
{
//默认的HSTS值为30天。您可能希望在生产场景中更改此值,请参阅https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseRouting();
app.UseMiddleware();
app.UseHttpsRedirection();
app.UseRequestLocalization(app.ApplicationServices.GetService().Value);
app.UseEndpoints(端点=>
{
endpoints.MapControllers();
MapControllerOute(“默认值”,“{controller=Auth}/{action=RequestVerificationCode}/{id?}”);
});
app.UseSwagger();
app.UseSwaggerUI(c=>
{
c、 SwaggerEndpoint(“/swagger/v1/swagger.json”,“GetAJobToday”);
});
}
}
但当我运行它时,它会抛出此异常:


AggregateException:无法构造某些服务(验证服务描述符“ServiceType:Swashback.AspNetCore.Swagger.ISwaggerProvider生存期:瞬态实现类型:Swashback.AspNetCore.SwagggerGen.SwagggerGenerator”时出错):无法比较数组中的两个元素。)(验证服务描述符“ServiceType:Swashback.AspNetCore.SwagggerGen.ISchemaRegistryFactory生存期:瞬态实现类型:Swashback.AspNetCore.SwagggerGen.SchemaRegistryFactory”时出错:未能比较数组中的两个元素。)

将Swashback.AspNetCore和Swashback.AspNetCore.Filters升级到V5.0.0-rc2解决了问题。

将Swashback.AspNetCore升级到最新版本V5.0.0-rc4解决了问题


我认为您需要Swashback 5.0.0-rc2与.NET Core 3.0一起使用。升级到新版本时,首先要跟进的是哪些外部软件包可用于新版本,并且询问一个关于它的问题感觉非常不舒服。a应该包括这一点。@LGSon-我很感谢穆罕默德·法哈德·纳迪姆写了这篇文章estion,它为我节省了一堆时间。对我来说,阅读这个问题就是研究:-)@AndrewShepherd你是说在升级主框架版本之前,你从来没有检查过你的组件是否可以与该升级一起工作?@LGSon-你将你的情况投射到堆栈溢出的其他人身上。在我的例子中,我试图学习一些新的东西,并且正在使用“ASP.NETCore2.0”一书中的一个示例。当错误出现时,我不知道我是做错了什么,还是其他问题。是的,我最终可以解决这个问题,但由于这个问题,我节省了时间,可以专注于我的目标,那就是理解虚张声势。