I upgraded to the latest version today and now all my recurring jobs give this error:
System.Reflection.TargetInvocationException
Exception has been thrown by the target of an invocation.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.NullReferenceException: Object reference not set to an instance of an object.
at System.Web.UI.Page.get_Server()
at ASP.hangfirerecurringtasks_recurringjobs_aspx…ctor()
— End of inner exception stack trace —
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Hangfire.JobActivator.ActivateJob(Type jobType)
at Hangfire.Common.Job.Activate(JobActivator activator)
Not sure but think I’ve got a dll missing? Can anyone help? Thanks
From the stack trace it looks like you are creating your recurring jobs in the constructor of RecurringJobs.aspx and that part of the job is calling the get method of the Server property of the page, which is throwing a null reference exception. Is that correct ?
I’m not sure what the lifecycle of the System.Web.UI.Page.Server HttpServerUtility is, but I’d expect that it is torn down upon an IIS recycle which has likely happened when you updated. (Or possible even after each request)
I’m not sure you’ll be able to get much help without showing some of the code from that page.
Does the ReportFunctions.BuildQuickReportsStatsStepOne method use any of the HttpServerUtility methods ? (Such as HtmlEncode / HtmlDecode, UrlEncode / UrlDecode or MapPath)
Can you attach a remote debugger and break on the exception ?
As you can see, the fully qualified type name is stored when the job is serialised which includes the assembly. Asp.Net web pages are compiled into a temporary assembly and when that page changes, so does the assembly name. (Depending on how you upgrade your site, the existing assembly may be kept around to finish serving existing requests while the new assembly serves new requests.)
You should be able to solve your problem by moving the BuildQuickReportStatsStepOne method / job into its own project / assembly. This will which will not change when your pages are recompiled. The issue will however occur if you change this assembly and either the assembly name or the version number changes. (Or the job’s method signature)
Thanks for the pointers - will let you know if this doesn’t resolve the issue. With the previous version of hangfire, the jobs weren’t serialised in this way.
Note: with previous version of hangfire, jobs were listed in dashboard as BuildQuickReportStatsStepOne etc but now, in new version, as hangfirerecurringtasks_recurringjobs_aspx.BuildQuickReportStatsStepOne.
Hello, I have the same problem.
Could you please elaborate how or what you mean by putting all the methods into their own assembly?
Any example for this ?