I guess here several problems, the main it's hangfire throw this exception when the application starts.
Exception thrown: 'System.ArgumentNullException' in Hangfire.SqlServer.dll.
The application still running but it's not good for sure. And the second one, I realized that in the hangfire dashboard there are registered two servers instead of only one. I only start working with hangfire, please help me figure out what is going on.
Here how I register hangfire in startup and use it.
ConfigureServices
//HangFire
services.AddHangfire(configuration => configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSqlServerStorage(Configuration.GetConnectionString("HangfireConnection"), new SqlServerStorageOptions
{
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
QueuePollInterval = TimeSpan.Zero,
UseRecommendedIsolationLevel = true,
DisableGlobalLocks = true,
}));
services.AddHangfireServer(x => new BackgroundJobServerOptions {
ShutdownTimeout = TimeSpan.FromHours(24),
ServerTimeout = TimeSpan.FromHours(24)
});
Configure
//HangFire
app.UseHangfireServer();
app.UseHangfireDashboard();
app.UseEndpoints(endpoints => {
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
endpoints.MapHangfireDashboard();
});
BackgroundJob.Enqueue(() => Console.WriteLine("Hello world from Hangfire!"));