Question

I'm trying to move my APN backoffice from PHP to C# for performance issue. Bear with me, I'm new to C# and mono.

I've just downloaded MonoDevelop 2.8.6.4 and APNS-sharp merge 26 on my OSX 10.7.2

I opened the entire solution with all libraries and test executables and built the entire solution without errors. I modified the fields (token id, cert file, ...) in the Program.cs in JdSoft.Apple.Apns.Notifications.Test to meet my specs. After a few tries I managed to get my certificate file OK and the connection to Apple servers is now up. I see the message saying I'm connected in the output of the application.

Probleme comes now. Everytime the application tries to send a message to Apple I get the error "A Type load exception has occured". I tried a little debug and the error seems to come from the NotificationPayload constructor.

Doing step by step follow up, it appears the NotificationAlert is correctly instantiated inside the NotificationPayload constructor. The error appears when coming back to the Notification constructor where the Payload member appears in the debugger as "A type load exception has occurred." instead of an object.

From there the Notification object ends up with the same behavior.

From my research on the Internet this could come from the version of Newtonsoft.Json.Compact.dll but I have no idea what to do with this piece of information.

For information I can see the same error when running the compiled test on my CentOS server.

And for more information the application message (changed ex.Message to ex.ToString() in the test program to get a full error) :

Notification Queued!
Sleeping 15000 milliseconds before next Notification...
Connecting...
Connected...
Error: System.TypeLoadException: A type load exception has occurred.
at JdSoft.Apple.Apns.Notifications.Notification.ToBytes () [0x0006c] in /Users/laurent/Downloads/Redth-APNS-Sharp-595275f 2/JdSoft.Apple.Apns.Notifications/Notification.cs:90 
at JdSoft.Apple.Apns.Notifications.NotificationChannel.Send (JdSoft.Apple.Apns.Notifications.Notification notification) [0x00000] in /Users/laurent/Downloads/Redth-APNS-Sharp-595275f 2/JdSoft.Apple.Apns.Notifications/NotificationChannel.cs:371 
at JdSoft.Apple.Apns.Notifications.NotificationConnection.workerMethod () [0x00035] in /Users/laurent/Downloads/Redth-APNS-Sharp-595275f 2/JdSoft.Apple.Apns.Notifications/NotificationConnection.cs:381

I didn't put the code, as I didn't change anything from the one you can see at https://github.com/Redth/APNS-Sharp.

I send an SOS to all mono guru around.

Have a nice day fellow developers and thanks in advance for your help and time. Any suggestion is gladly welcome.

Was it helpful?

Solution

(As the OP can't post the answer himself...)

In this particular case, the solution was to fetch the latest version of Newtonsoft.Json.Compact.dll.

In general, you need to try to get as much information from the exception as possible, to find out what it was trying to load - then check that the problematic library is present, and that you've got the version everything else expects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top