I'm currently working on a project that is split into five ASP.NET Core 2.2 web apps. One of the web apps is a dedicated Hangfire server, and another one is a dedicated IoT server. The IoT server needs to occasionally enqueue background jobs to the Hangfire server. When I was testing it out the other day for the first time, I got a weird exception that Hangfire's
JobStorage.Current property is not set.
This surprised me because I made sure to add it and use it in the
Startup class. I went back into the class and sure enough, it was there. I then compared it with the
Startup classes for the other web apps (which were working fine) and it was identical. Nevertheless the exception was being thrown.
After some searching online and getting nowhere I stumbled, really by chance, onto a bug report on Hangfire's site. It's by a user named Poly and he had the exact same issue as me. Luckily for me, he had a workaround for it by injecting the
IServiceProvider in the
Configure method and then using it to get an instance of the
JobStorage. This initializes the property and everything works great after that.
Sadly, his post is from October of 2016, so almost three years later, this still seems to be an issue in Hangfire.