一个 asp.net core 应用在启动时失败退出,报错信息如下:
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at Cnblogs.WebAPI.Program.Main(String[] args) in /src/Cnblogs.WebAPI/Program.cs:line 12
Aborted (core dumped)
Program.cs 中对应的第12号代码是
CreateHostBuilder(args).Build().Run();
请问如何解决这个问题?
是 Startup.ConfigureServices
中重复注册 HttpClient 的代码引起的,对同样的类型执行了2次 services.AddHttpClient
。