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

Re: UseRecurringJob("recurringjob.json") Newtonsoft.Json.JsonSerializationException

Open ghost opened this issue 7 years ago • 13 comments

Hello,

We are using your excellent hangfire extension.However, we are stuck at trying to get the recurringjob.json method of recurring jobs. we get the following error:

Newtonsoft.json.JsonSerializationException 'Error converting value to type 'System.Type.Path' [0].job-type, line 5, position 69'

Inner exception ArgumentException: Could not cast or convert from System.String to System.Type.

it would be awesome if we could get some help with this :)

Thanks

ghost avatar Nov 03 '17 16:11 ghost

Did you find out? I'm getting the same error....

claudiobottari avatar Jan 26 '18 08:01 claudiobottari

No I didn't..was hoping for a response

ghost avatar Jan 26 '18 09:01 ghost

@christophertodd
u can paste your json file content here,it will helpe me to check the error.

icsharp avatar Jan 26 '18 09:01 icsharp

Since it was urgent to me to fix this... I changed the receiving object definition for the property that gave me this error (from System.Type to string) to avoid this exception. It's a workaround that you may use as well...

claudiobottari avatar Jan 26 '18 09:01 claudiobottari

@claudiobottari Got it!

icsharp avatar Jan 26 '18 09:01 icsharp

Hi @icsharp thanks for getting in touch!

recurringjoberror

we are using: "HangFire" Version: 1.6.17 "Microsoft.AspNetCore" Version= 2.0.1

please see a pic of the error we have recreated and please find the json below:

[ { "job-name": "My Job1", "job-type": "Hangfire.Samples.MyJob1, Hangfire.Samples", "cron-expression": "*/1 * * * ", "timezone": "China Standard Time", }, { "job-name": "My Job2", "job-type": "Hangfire.Samples.MyJob2, Hangfire.Samples", "cron-expression": "/5 * * * ", "job-data": { "IntVal": 1, "StringVal": "abcdef", "BooleanVal": true, "SimpleObject": { "Name": "Foo", "Age": 100 } } }, { "job-name": "Long Running Job", "job-type": "Hangfire.Samples.LongRunningJob, Hangfire.Samples", "cron-expression": "/2 * * * *", "job-data": { "RunningTimes": 300 } } ]

ghost avatar Jan 26 '18 10:01 ghost

@christophertodd
see unit test I added ,it passed. Maybe you can serialize RecurringJobJsonOptions instance and get the job-type string as @claudiobottari said .

icsharp avatar Feb 07 '18 05:02 icsharp

@claudiobottari can you explain how you did perform it?

russosalv avatar Feb 07 '18 13:02 russosalv

Hi there and sorry for the late reply. Since there's clearly an issues on deserializing certain types, I worked around this limitation updating the property which raised the exception to be a simple string... that was enough to make the serialization/deserialization work. At that point I converted by myself the string to the required type. Is is clear?

claudiobottari avatar Feb 09 '18 16:02 claudiobottari

Hi Guys.. I was getting this error while setting up a simple project.. The actual recurring job was a new project in the same solution. The fix was simply to add the project as a reference in the parent project. (Right click the parent project references > Add reference > Select the recurringjob Project) Hope this helps somebody !

simplysiby avatar Aug 13 '18 07:08 simplysiby

I also encountered this problem. How to solve it? Is there a demo? thank you

wangboshun avatar Nov 17 '19 10:11 wangboshun

If anyone else runs into this issue, here is what solved it for me: Use the AssemblyQualifiedName property to discover the full name of your class and use that in the job-type property. I added this bit of code in my startup before attempting to do anything with Hangfire: string myTask = typeof(MyTask).AssemblyQualifiedName I examined "myTask" in the debugger and that gave me a string that looked like: "MyTaskProject.Tasks.MyTask, MyTask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" That string satisfied the type conversion. I found that it still worked after removing the Version, Culture and PublicKeyToken attributes, so my final job-type value ended up being: "MyTaskProject.Tasks.MyTask, MyTask".

kevinmatspie avatar Jul 25 '23 17:07 kevinmatspie

@kevinmatspie you're SUUUUUUUPER HEROOOOOOOOOOOOOO, I got stuck a lot of time thanks

MohammedSafi96 avatar Sep 14 '23 12:09 MohammedSafi96