# Recurring jobs do not automatically get retried after application crash (.net core service)

**URL:** <https://discuss.hangfire.io/t/recurring-jobs-do-not-automatically-get-retried-after-application-crash-net-core-service/9160>\
**Category:** question\
**Tags:** recurring, dotnetcore\
**Created:** [May 18, 2022, 5:46pm UTC](https://discuss.hangfire.io/t/recurring-jobs-do-not-automatically-get-retried-after-application-crash-net-core-service/9160 "2022-05-18T17:46:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul2](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/paul2/32/2919_2.png) [@paul2](https://discuss.hangfire.io/u/paul2)\
**Post date:** [May 18, 2022, 5:46pm UTC](https://discuss.hangfire.io/t/recurring-jobs-do-not-automatically-get-retried-after-application-crash-net-core-service/9160/1 "2022-05-18T17:46:55Z")

</div>

Hi,  
I am using hangfire (1.7.28) in a .NET 6 service with Hangfire.PostgreSql for storage.  
Scheduling new jobs and executing/retrying them works fine as long as the service is running. If it crashes though none of the instances that where running at the time of the crash are getting retried on startup.  
As far as i understand the documentation the expected behaviour would be that they rerun.

I am using custom states in case that matters but also experience the problem if the job is in the “Processing” state at time of the crash.

Here is my setup:

```auto
services.AddHangfire((provider, config) =>
{
config.UsePostgreSqlStorage(configurationRoot.GetValue<string>("DBConnectionString"))
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseFilter(new ElectStateFilter(provider.GetRequiredService<ConfigurationStorageProvider>(), provider.GetRequiredService<ILogger<ElectStateFilter>>())); 
});
services.AddHangfireServer();

GlobalStateHandlers.Handlers.Add(new RemoteJobInitiatedState.Handler());
GlobalStateHandlers.Handlers.Add(new RemoteJobProcessingInitiatedState.Handler());
GlobalStateHandlers.Handlers.Add(new RemoteJobTransferInitiatedState.Handler());
GlobalStateHandlers.Handlers.Add(new DatabaseInsertInitiatedState.Handler());

```

Looking at the hangfire db i can see the in-progress jobs in the table “job” but they are obviously not getting picked up again.

What am i missing?

Thanks

---

<div class="post-metadata">

**Author:** ![paul2](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/paul2/32/2919_2.png) [@paul2](https://discuss.hangfire.io/u/paul2)\
**Post date:** [May 18, 2022, 7:19pm UTC](https://discuss.hangfire.io/t/recurring-jobs-do-not-automatically-get-retried-after-application-crash-net-core-service/9160/2 "2022-05-18T19:19:46Z")

</div>

I found the reason why the retries were not working…

I had one dependency in my job class that was initially registered after the call to AddHangFire and AddHangfireServer. Registering it before the call fixed the issue.  
It would be real nice if the server would log an error somewhere if it can´t construct the instance for the job execution.

For completeness sake here is an example of the issue and the fix

Job class constructor:

```auto
public HangFireJob(IDependency dep )
{
    _dep = dep;
}

```

Initial setup process that caused the issue:

```auto
services.AddHangfire((provider,config) =>
{ ... }
services.AddHangfireServer()
services.AddSingleton<IDependency>(new Dependency())

```

Working setup process:

```auto
services.AddSingleton<IDependency>(new Dependency())
services.AddHangfire((provider,config) =>
{ ... }
services.AddHangfireServer()

```
