.net core 随机发生的问题:';无法解析类型(…)';火上浇油

.net core 随机发生的问题:';无法解析类型(…)';火上浇油,.net-core,dependency-injection,inversion-of-control,ioc-container,hangfire,.net Core,Dependency Injection,Inversion Of Control,Ioc Container,Hangfire,我遇到了一个奇怪的问题。在尝试激活“AW.Services.Jobs.SendSmsJob”时,我有时(完全随机)会遇到无法解析类型“AW.Services.Interfaces.ISmsService”的服务的错误。当我在这个失败的作业的仪表板上单击requeue时,它要么再次失败,要么成功完成。这是随机发生的,我不知道发生了什么 我在IoC中注册了我的接口,当然是这样的:services.AddTransient() 我正在使用以下软件包版本: .NET核心3.1 HangfireV1.7

我遇到了一个奇怪的问题。在尝试激活“AW.Services.Jobs.SendSmsJob”时,我有时(完全随机)会遇到无法解析类型“AW.Services.Interfaces.ISmsService”的服务的错误。当我在这个失败的作业的仪表板上单击requeue时,它要么再次失败,要么成功完成。这是随机发生的,我不知道发生了什么

我在IoC中注册了我的接口,当然是这样的:
services.AddTransient()

我正在使用以下软件包版本:

  • .NET核心3.1
  • HangfireV1.7.9
  • Hangfire.AspNetCore v1.7.9
  • Hangfire.Console v1.4.2
  • Hangfire.PostgreSql v1.6.4.1
startup.cs中My hangfire的配置如下:

services.AddHangfire(配置=>
{
config.UsePostgreSqlStorage(配置[“AW_API_DB_CONNECTIONSTRING]”);
config.UseConsole();
});
GlobalConfiguration.Configuration.UseSerializerSettings
(
新JsonSerializerSettings
{
ReferenceLoopHandling=ReferenceLoopHandling.Ignore
}
);
(...)
app.UseHangfireServer(新的BackgroundJobServerOptions
{
WorkerCount=背景处理WorkerCount
});
app.UseHangfireServer(新的BackgroundJobServerOptions
{
WorkerCount=背景处理WorkerCount,
队列=新[]{JobQueueTypes.Transactions}
});
app.UseHangfireDashboard(“/dashboard”),新的仪表板选项
{
Authorization=new[]{new AgriWalletDashboardAuthFilter()},
我
下面我从hangfire的仪表板复制了整个日志:

在尝试激活“AW.Services.Jobs.SendSmsJob”时无法解析类型“AW.Services.Interfaces.ISmsService”的服务。System.InvalidOperationException:在尝试激活“AW.Services.Jobs.SendSmsJob”时无法解析类型“AW.Services.Interfaces.ISmsService”的服务。位于 Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider 供应商)在 Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider 提供程序,类型instanceType,对象[]参数)位于 Hangfire.Server.CoreBackgroundJobPerformer.Perform(PerformContext (上下文) 在Hangfire.Server.BackgroundJobPerformer.c_uuuDisplayClass9_0.b_uu0()上 位于Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter 过滤器,执行上下文预文本,在 Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter 过滤器,执行上下文预文本,函数1(续) Hangfire.Server.BackgroundJobPerformer.PerformJobWithFilters(PerformContext 上下文,IEnumerable`1筛选器)位于 Hangfire.Server.BackgroundJobPerformer.Perform(PerformContext上下文) 在Hangfire.Server.Worker.PerformJob(BackgroundProcessContext, IStorageConnection连接,字符串jobId)


从netcore2迁移到netcore3可能会导致依赖项注入问题。请验证project Program.cs和Startup.cs类


事实上,这导致了问题:)