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

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

Open
ghost opened this issue Nov 3, 2017 · 13 comments

Comments

@ghost
Copy link

ghost commented Nov 3, 2017

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

@claudiobottari
Copy link

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

@ghost
Copy link
Author

ghost commented Jan 26, 2018

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

@icsharp
Copy link
Owner

icsharp commented Jan 26, 2018

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

@claudiobottari
Copy link

claudiobottari commented Jan 26, 2018

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...

@icsharp
Copy link
Owner

icsharp commented Jan 26, 2018

@claudiobottari
Got it!

@ghost
Copy link
Author

ghost commented Jan 26, 2018

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

@icsharp
Copy link
Owner

icsharp commented Feb 7, 2018

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

@russosalv
Copy link

@claudiobottari can you explain how you did perform it?

@claudiobottari
Copy link

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?

@simplysiby
Copy link

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 !

@wangboshun
Copy link

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

@kevinmatspie
Copy link

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".

@MohammedSafi96
Copy link

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

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

No branches or pull requests

7 participants