错误“发生类型加载异常。”将 apns-sharp 与单声道一起使用

发布于 2025-01-05 15:20:03 字数 1801 浏览 8 评论 0原文

由于性能问题,我正在尝试将我的 APN 后台从 PHP 迁移到 C#。请耐心等待,我是 C# 和 mono 的新手。

我刚刚在 OSX 10.7.2 上下载了 MonoDevelop 2.8.6.4 和 APNS-sharp merge 26,

我打开了包含所有库和测试可执行文件的整个解决方案,并构建了整个解决方案,没有错误。我修改了 JdSoft.Apple.Apns.Notifications.Test 中 Program.cs 中的字段(令牌 ID、证书文件等)以满足我的规范。 经过几次尝试,我成功获得了证书文件,并且与 Apple 服务器的连接现已建立。我在应用程序的输出中看到一条消息说我已连接。

问题来了。每次应用程序尝试向 Apple 发送消息时,我都会收到错误“发生类型加载异常”。我尝试了一些调试,错误似乎来自NotificationPayload构造函数。

逐步跟进,看来NotificationAlert已在NotificationPayload构造函数内正确实例化。返回到通知构造函数时会出现错误,其中 Payload 成员在调试器中显示为“发生类型加载异常”。而不是一个物体。

从那里,Notification 对象最终会产生相同的行为。

根据我在互联网上的研究,这可能来自 Newtonsoft.Json.Compact.dll 的版本,但我不知道如何处理这条信息。

有关信息,我在 CentOS 服务器上运行编译测试时可以看到相同的错误。

有关应用程序消息的更多信息(在测试程序中将 ex.Message 更改为 ex.ToString() 以获取完整错误):

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

我没有放置代码,因为我没有更改您可以看到的任何内容在 https://github.com/Redth/APNS-Sharp

我向周围所有单声道大师发出求救信号。

祝各位开发人员度过愉快的一天,并提前感谢您的帮助和时间。任何建议都非常欢迎。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不打扰别人 2025-01-12 15:20:03

(因为OP无法自己发布答案...)

在这种特殊情况下,解决方案是获取最新版本的Newtonsoft.Json.Compact.dll。

一般来说,您需要尝试从异常中获取尽可能多的信息,以找出它试图加载的内容 - 然后检查有问题的库是否存在,以及您是否获得了其他所有内容所期望的版本。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文