icsharp / Hangfire.RecurringJobExtensions

Extensions for Hangfire to build RecurringJob automatically
MIT License
181 stars 36 forks source link

Unable to use context.GetJobData in any case #11

Open Hirikon opened 5 years ago

Hirikon commented 5 years ago

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 commented 3 years ago

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

Sajeewa-Dissa commented 3 years ago

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 commented 1 year ago

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 commented 3 months ago

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 commented 3 months ago

This repo Is not mantained for me

timshepherd-academy commented 3 months ago

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