-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InvalidOperationException: JobStorage.Current property value has not been initialized #1991
Comments
This is because you are accessing the JobStorage before it has been fully initialized. Perhaps you try to add/edit jobs when starting the application. services.AddHostedService<AddingJobsService>(); or set the static JobStorage manually before accessing it JobStorage.Current = new SqlServerStorage("connectionString"); |
Hi, I had the same issue as @regisoft. I started digging in the decompiled code from Hangfire and found something: adding the following line of code solved everything:
(This is from the This line needs to be run before any Hangfire-related sentence is run (i.e.: before instantiating a I'd say this looks like some kind of bug in the side of the Hangfire package, since it doesn't make any sense to have to run this code on our side. If any, I'd at least appreciate to have this added to the documentation, if not fixed. Funnily enough, I have two different projects with ASP.NET Core and Hangfire: the first of them didn't need this sentence but the second one did, and I cannot tell why this is the case. In any case, manually setting |
Thanks @akarboush and @igsoblechero for the input.
|
@igsoblechero solution would work too, but I would advise against it since it is an antipattern and could results in more than one copy of singleton services being created. See
Another solution would be to create background jobs in the |
Maybe a put a worse example than expected, but this is how I finally left my code because I wanted to add a Anyway, I had the same issue putting the |
Btw, @akarboush, thanks for letting me know that antipattern! |
@igsoblechero adding The creation of the job(s) can be easily done in the public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IRecurringJobManager manager)
{
manager.AddOrUpdate("id", () => Console.WriteLine(), Cron.Daily);
......... |
Okay, I have some news from your proposal. Efectively, if I'm using instantiating a |
In my case the exception is thrown on this statement:
We never used XXXJobManager. |
and same for |
I've had the same issue and Sergey Odinokov helped me a lot! #1967 |
As @akarboush and #1967 proposed, i replaced the static |
I discovered that if ".UseSqlServerStorage" is not on the first line of the configuration, it will cause this problem. This is what I originally had: This solved the problem: |
@crossr1 unfotunatly that did not fix my issue but @igsoblechero your solution of adding
to my start up file did help me. I also have two MVC projects and my first one works just fine but the second one requires this line of code to work. Perhaps the fact that both of my Web applications are using the same sql database might have something to do with it. Anyway below is my start up configuration of hangfire
Thank you @igsoblechero |
Thanks @igsoblechero and @akarboush both your solutions helped a lot but the application I have doesn't have straightforward |
Hi
We are on .net6 and Hangfire 1.7.28.
We use the minimal api ... (no more startup.cs only program.cs)
With "UseHangfireServer" our program works. But "UseHangfireServer" is obsolete.
With "AddHangfireServer" we get...
Any idea?
The text was updated successfully, but these errors were encountered: