Hangfire Job throws - System.TypeLoadException
Asked Answered
S

0

6

I have used Hangfire (1.6.17) on .net core application for scheduling and recurring jobs…it works fine for 2 3 job en-queued but when it get more than 2 or 3 jobs at same time to be execute, some job gets failed and some goes in retry section and some of them gets success.

Exception
Failed
Can not change the state to ‘Enqueued’: target method was not found.

System.TypeLoadException

Could not load type ‘MyApp.Repository.AsyncScrumRepository.AsyncScrumRepository’ from assembly ‘MyApp.Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’.

System.TypeLoadException: Could not load type ‘MyApp.Repository.AsyncScrumRepository.AsyncScrumRepository’ from assembly ‘MyApp.Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’.
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
at Hangfire.Storage.InvocationData.Deserialize()

When I manually triggered that failed and retry section job via UI Dashboard, by 1 or 2 trigger, all job gets success. I am using this in production server and didn’t expect this kind of issue and now I have to trigger jobs in my production manually.

screenshot of exception

Here is the screenshot of exception

I have searched the Git and blog discussion

  1. github issue 430

  2. same issue

  3. related issue

I have updated my application - Having same version of Hangfire in every project of solution, every dependent method to be called from Hangfire job are now public method and having specific queue name for my jobs.

Surfacetosurface answered 11/12, 2017 at 4:48 Comment(1)
I found a workaround by using BackgroundJob.Enqueue over BackgroundJob.Schedule which in my case happened to work, I understand that it might not be an option in most other cases though. Very frustrating issue.Debris

© 2022 - 2024 — McMap. All rights reserved.