Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use context.GetJobData in any case #11

Open
Hirikon opened this issue Jan 24, 2019 · 6 comments
Open

Unable to use context.GetJobData in any case #11

Hirikon opened this issue Jan 24, 2019 · 6 comments

Comments

@Hirikon
Copy link

Hirikon commented Jan 24, 2019

Dear all,

when i try to use context.GetJobData the following error occurs:

Hangfire.Common.JobLoadException: Could not load the job. See inner exception for the details. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: typeName
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()
--- End of inner exception stack trace ---
at Hangfire.Storage.InvocationData.Deserialize()
at Hangfire.RecurringJobExtensions.RecurringJobInfoStorage.InternalFind(String recurringJobId, Dictionary`2 recurringJob)
at Hangfire.RecurringJobExtensions.RecurringJobInfoStorage.FindByRecurringJobId(String recurringJobId)
at Hangfire.RecurringJobExtensions.PerformContextExtensions.GetJobData(PerformContext context)
at Hangfire.RecurringJobExtensions.PerformContextExtensions.GetJobData(PerformContext context, String name)
at Hangfire.RecurringJobExtensions.PerformContextExtensions.GetJobData[T](PerformContext context, String name)
at Elpedison.ETIS.Core.API.LongRunningJob.Execute(PerformContext context) in C:\Users\k.chirikakis\Source\Repos\ETIS\Elpedison.ETIS\Elpedison.ETIS.Core.API\Jobs

Can you please help us?

@ClarkGUO
Copy link

I also encountered the same problem, have you solved it? @Hirikon

@Sajeewa-Dissa
Copy link

Sajeewa-Dissa commented Feb 10, 2021

We found this issue when trying to pick up scheduled job info using config.UseRecurringJob("recurringjob.json"). The source of the bug is something to do with Json serialization in RecurringJobInfoStorage.cs InternalFind method. It prevents SetJobData and GetJobData from working.

Our workaround was to remove SetDataCompatibilityLevel(CompatibilityLevel.Version_170) from the services.AddHangfire middleware configuration chained method. Either remove it or set it to CompatibilityLevel.Version_110. Hope this helps someone or aids in solving the issue. Hangfire version 1.7.* and Hangfire.RecurringJobExtensions version 1.1.6 running in a .Net 5 project.

@andreatosato
Copy link

andreatosato commented May 18, 2023

I make this workaround in RecurringJobInfoStorage in InternalFind method:

var serializedJobRecurring = JobHelper.FromJson<InvocationDataRecurring>(recurringJob["Job"]);
var serializedJob = new InvocationData(serializedJobRecurring.Type, serializedJobRecurring.Method, JobHelper.ToJson(serializedJobRecurring.ParameterTypes), JobHelper.ToJson(serializedJobRecurring.Arguments));
var job = serializedJob.Deserialize();

Then add this class

/// <summary>
	/// 
	/// </summary>
	public class InvocationDataRecurring
	{
		/// <summary>
		/// 
		/// </summary>
		[JsonProperty("t")]
		public string Type { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("m")]
        public string Method { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("p")]
        public List<string> ParameterTypes { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("a")]
        public List<string> Arguments { get; set; }
	}

@timshepherd-academy
Copy link

Got this issue today with setting the SetDataCompatibilityLevel(CompatibilityLevel.Version_180) in my project - I didn't set the Compatibility level for Version_170 so I've only seen this issue starting today.

I am stuck using this library - does the owner have any plans for fixing this?? If that code from @andreatosato works, shouldn't there be a PR for it?

@andreatosato
Copy link

This repo Is not mantained for me

@timshepherd-academy
Copy link

Then how did you make those changes? Did you download/fork the codebase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants