Hangfire - Unable to resolve services [Answered]

Working with Hangfire. I have a plugin service which has an InitializeAsync method that looks like this:
public override ValueTask<Result> InitializeAsync(IServiceProvider serviceProvider, CancellationToken ct = default)
{
    using var scope = serviceProvider.CreateAsyncScope();
    _ = scope.ServiceProvider.GetRequiredService<ILogger<ReportBuilderService>>();
    _ = scope.ServiceProvider.GetRequiredService<ReportBuilderContext>();
    _ = scope.ServiceProvider.GetRequiredService<DataPluginContext>();
    _ = scope.ServiceProvider.GetRequiredService<InContactService>();
    _ = scope.ServiceProvider.GetRequiredService<IOptions<ReportBuilderConfig>>().Value;

    // This job runs every minute, polling the queue table to see
    // if there are new records and, if so, running them.
    RecurringJob.AddOrUpdate<ReportBuilderService>
    (
        recurringJobId: "ExecuteQueueItems",
        service => service.ProcessQueue(CancellationToken.None),
        Cron.Minutely
    );
    RecurringJob.AddOrUpdate<ReportBuilderService>
    (
        recurringJobId: "AbortCancelledJobs",
        service => service.CancelItems(CancellationToken.None),
        Cron.Minutely
    );

    return ValueTask.FromResult(Result.FromSuccess());
}

I request and dump those services as a test to make sure that all of them are there, even though I've independently verified by examining the service collection as it's being built. All of them pass. However, when Hangfire tries to request them, it's unable to resolve some service. I cannot see which one though because the exception appears to be swallowed. I do get this exception though:
[09:52:45 FTL] [IncontactReports.Runtime.Program] [{}] Host terminated unexpectedly
System.Exception: Plugin initialization Error: One or more errors occurred.
[0]:    RestResultError { Message = REST request failed. See inner error object for details., Error = RestResultError { Message = REST request failed. See inner error object for details., Error =  } }
[1]:    PluginInitializationFailed { Message = Initialization of ReportBuilderPlugin (ReportBuilderPlugin) failed: One or more of the plugin's dependencies failed to initialize., Descriptor = ReportBuilderPlugin }

   at IncontactReports.Runtime.InContactBot.StartAsync(CancellationToken stoppingToken) in D:\Projects\apps\TAFS\InContactReports\IncontactReports.Runtime\InContactBot.cs:line 83
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at IncontactReports.Runtime.Program.Main() in D:\Projects\apps\TAFS\InContactReports\IncontactReports.Runtime\Program.cs:line 145
   at IncontactReports.Runtime.Program.Main() in D:\Projects\apps\TAFS\InContactReports\IncontactReports.Runtime\Program.cs:line 146

It's failing to initialize the ReportBuilderPlugin, an error which is returned when InitializeAsync() throws or returns an unsuccessful result.
Was this page helpful?