Can not change the state to "Enqueue" target method was not found

I’m using Hangfire with MySQL server. When I schedule a job, it often failed because of this error The type NewsBusiness does not contain a method with signature DeleteNewsPhysical(Int32). Even though the method is contained in that class and after a few try the job run successfully. Does anyone know the reason behind the fail try?

BackgroundJob.Schedule(() => this.DeleteNewsPhysical(id), TimeSpan.FromSeconds(5));
public void DeleteNewsPhysical(int newsId)
{}

Did you find a solution to this yet?
I have a similar issue. I work with dependency injection as documented here: http://docs.hangfire.io/en/latest/background-methods/using-ioc-containers.html
(maybe this already fixes the problem for you? Or did you try calling a static method instead?)

In my case it throws a TypeLoadExceptions, but only sometimes. Sometimes hangfire works just fine, but other times it fails through all the retries for no reason, or at least none I can find. It get’s especially flaky when I send a lot of calls at the same time (like 50 or more).

Maybe someone else here knows what to do?
This is what my code looks like btw.

The call:

this._backgroundJobClient.Schedule(x => x.RunAction(someId, someDict), Convert.ToDateTime(someDateTimeString));

And the method that’s called:

public void RunAction(Guid someId, Dictionary<string, object> someDict) { //some stuff }

I work with Autofac for dependency injection and the whole project is a windows service.

1 Like

Thanks for your reply. I solved the problem which is a stupid mistake I made. My local and dev environment is using the same database and the problem is the job try to run in the dev environment which I did not deploy my code yet.

Oh my… yeah we work on this as a team so we have multiple test services running but using the same database. I just turned all but one service off and bam! It works perfectly.
Thanks so much for the reply, I would never have figured out that was to problem!

Please help me understand this. If we have multiple services and if the code isn’t deployed then where would the hangfire service search the delegate method? only in the deployed and running service right?
If there are multiple services running, then each service would have the instance of hangfire and it should work