Hangfire Discussion

Method not found: 'Void Hangfire.RecurringJob.AddOrUpdate

Tags: #<Tag:0x00007f8501ee2540>


We’ve been using Hangfire for years with great success. Currently, we are trying to convert some of the methods that hangfire calls to Async as they are remote API calls that can take a while and hog threads in our Saas application. We are using the latest version of Hangfire 1.6.22

Here’s the error:

Method not found: 'Void Hangfire.RecurringJob.AddOrUpdate(System.String, System.Linq.Expressions.Expression`1<System.Func`1<System.Threading.Tasks.Task>>, System.String, System.TimeZoneInfo, System.String)'.

When calling this method in Startup.cs, the error is thrown.

public void ScheduleTasks() {

            var dbContext = new InventoryMgmtContext();
            var storeFrontRepository = new Repository<StoreFront>(dbContext);
            storeFronts = storeFrontRepository.GetAll().ToList();

            foreach (var storeFront in storeFronts) {
                //storeFront.StoreFrontItemMappings = null;
                var syncErpWithNewOrUpdatedItemsTask = new SyncErpWithNewOrUpdatedItemsTask();
                RecurringJob.AddOrUpdate(storeFront.Description + ": Store Front to Mozzo: Items",
                    () => syncErpWithNewOrUpdatedItemsTask.Execute(storeFront),
                        Cron.Yearly(6), //once every June
                        "*/5 * * * *", //every 5 min 

The method signature it is calling is:
public async Task<ActionConfirmation<int>> Execute(StoreFront storeFront)


If I add a .Wait() (which I’ve read you should not have to, nor should do this) to the RecurringJob.AddOrUpdate invocation, I no longer receive that error, but another:


Fixed. I had an older version in the calling assembly that Startup.cs was in.