RecurringJob.AddOrUpdate JobLoadException

When I try to schedule a recurring job on startup, I get a JobLoadException:

                    RecurringJob.AddOrUpdate<ICOPAEDIHelper>("COPAEDI", copaEDIWorker => copaEDIWorker.DownloadAndProcessXMLFiles(JobCancellationToken.Null),
                    Cron.Daily(copaEDIScheduleTime.ToUniversalTime().Hour, copaEDIMinute));

But if I register a BackgroundJob with the same method, it works fine:

                    BackgroundJob.Enqueue<ICOPAEDIHelper>(copaEDIWorker => copaEDIWorker.DownloadAndProcessXMLFiles(JobCancellationToken.Null));

Here’s my interface with the method signature:

    public interface ICOPAEDIHelper
{
    void DownloadAndProcessXMLFiles(IJobCancellationToken cancellationToken);
}

If I modify my interface/signature and remove the IJobCancellationToken, everything works fine.

Here’s the stack trace:

And here’s the exception detail:

Hangfire.Common.JobLoadException

HResult=0x80131500
Message=Could not load the job. See inner exception for the details.
Source=Hangfire.Core
StackTrace:
at Hangfire.Storage.InvocationData.DeserializeJob()
at Hangfire.RecurringJobEntity…ctor(String recurringJobId, IDictionary2 recurringJob, ITimeZoneResolver timeZoneResolver, DateTime now) at Hangfire.RecurringJobExtensions.GetOrCreateRecurringJob(IStorageConnection connection, String recurringJobId, ITimeZoneResolver timeZoneResolver, DateTime now) at Hangfire.RecurringJobManager.AddOrUpdate(String recurringJobId, Job job, String cronExpression, RecurringJobOptions options) at Hangfire.RecurringJobManagerExtensions.AddOrUpdate(IRecurringJobManager manager, String recurringJobId, Job job, String cronExpression, TimeZoneInfo timeZone, String queue) at Hangfire.RecurringJob.AddOrUpdate[T](String recurringJobId, Expression1 methodCall, String cronExpression, TimeZoneInfo timeZone, String queue)
at ERMA2.Startup.setupCOPAEDIScheduledTask(IContainer container) in C:\Projects\ERMA2Clone\ERMA2\Startup.cs:line 166
at ERMA2.Startup.<>c__DisplayClass9_0.b__0() in C:\Projects\ERMA2Clone\ERMA2\Startup.cs:line 65
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()

Inner Exception 1:
InvalidOperationException: The type ERMA2BusinessLibrary.Models.ICOPAEDIHelper does not contain a method with signature DownloadAndProcessXMLFiles()

I’ve been struggling with this all day. Thank you for any help you can provide.

I’ve found a way around this. When I register the RecurringJob I don’t pass in any cancellation token.

Then periodically inside my job, I check the following:

                // check if the recurring job was cancelled
            List<RecurringJobDto> jobList;
            using (var connection = JobStorage.Current.GetConnection())
            {
                jobList = connection.GetRecurringJobs();

                RecurringJobDto copaEDIJob = jobList.Where(a => a.Id == "COPAEDI").FirstOrDefault();
                if (copaEDIJob != null && copaEDIJob.LastJobState == "Deleted")
                {
                    // stop processing
                }
            }