Hangfire.RecurringJobExtensions icon indicating copy to clipboard operation
Hangfire.RecurringJobExtensions copied to clipboard

Unable to use context.GetJobData in any case

Open Hirikon opened this issue 6 years ago • 6 comments

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?

Hirikon avatar Jan 24 '19 09:01 Hirikon

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

ClarkGUO avatar Jan 26 '21 08:01 ClarkGUO

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.

Sajeewa-Dissa avatar Feb 10 '21 10:02 Sajeewa-Dissa

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; }
	}

andreatosato avatar May 18 '23 10:05 andreatosato