Mono、带有 MarshalByRefObject 的可序列化对象
我正在尝试将 C# 应用程序移植到 .NET(客户端服务器),但遇到了序列化问题。
Linux 客户端序列化并对象,但 Windows 服务器无法反序列化它,并给出错误:
System.Runtime.Serialization.SerializationException
在类中找不到字段“MarshalByRefObject+__identity”
反序列化是通过 BinaryFormatter 完成的:
BinaryFormatter formatter = new BinaryFormatter();
formatter.Deserialize(data);
相关类具有 Serialized 属性,并且继承自 MarshalByRefObject。 如果我删除 MarshalByRefObject 的继承,它就可以正常工作。 在 Windows 中一切正常,因此我假设这是 Mono 特定的问题。
任何帮助/建议将不胜感激^_^
I'm attempting to port a C# application to .NET (client server), and am running into issues with serialization.
The Linux client serializes and object, but the Windows server is unable to deserialize it, giving the error:
System.Runtime.Serialization.SerializationException
Field "MarshalByRefObject+__identity" not found in class
Deserialization is done via BinaryFormatter:
BinaryFormatter formatter = new BinaryFormatter();
formatter.Deserialize(data);
The class in question has the Serializable attribute, and inherits from MarshalByRefObject. If I remove the inheritance of MarshalByRefObject, it works fine. Everything works fine in Windows, and so I am assuming this is a Mono specific issue.
Any help/advice would be greatly appreciated ^_^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
二进制序列化依赖于私有实现细节。 在您的情况下,私有字段 __identity。 由于 Mono 开发人员无权访问私有实现细节,这些细节有时会不匹配,因此二进制序列化在 .Net 和 Mono 之间并不总是兼容。
请使用 Mono 提交测试用例:
http://www.mono-project.com/Bugs
要解决此问题,您可以为您的类进行您自己的自定义序列化。
Binary serialization relies on private implementation details. In your case, the private field __identity. Because Mono developers do not have access to the private implementation details, these occasionally do not match, and thus binary serialization is not always compatible between .Net and Mono.
Please file a test case with Mono:
http://www.mono-project.com/Bugs
To work around this, you can do your own custom serialization for your class.