4

I have a server running on MS.NET and a client on Mono (this is a Unity3D engine) and when i try to BinaryFormatter().Deserialize an object like this:

   [Serializable]   
    public class Simulator  
    {
        public IDictionary<int, Task> tasks = new Dictionary<int, Task>(); 

the client side cannot found/load types: Dictionary, List... The same "client code" running under MS.NET works good i.e. does not have any exceptions during deserialization.

As i read from http://www.mono-project.com/FAQ:_Technical#Compatibility this is a common problem:

"If you are serializing your own classes, there is no problem, since you have control over the assemblies and classes being used for serialization. However, if you are serializing objects from the framework, serialization compatibility is not guaranteed, since the internal structure of those objects may be different. This compatibility is not even guaranteed between different MS.NET versions or Mono versions."

Does ProtoBuf-Net help to avoid/resolve this serialization/deserialization problem ?

4

1 回答 1

2

是的,像 protobuf-net 这样的外部序列化工具可以解决这个问题——事实上,一旦你在平台之间进行序列化(C++ 到 java 到 python 到 .net),框架版本就不再那么重要了。

所以是的:在 .NET 上加载时,在单声道/统一的 protobuf-net 中序列化的数据完全兼容。但是,应该注意的是BinaryFormatter,protobuf-net并不是直接的 1:1 等价物——每个都有略微不同的特性和行为。例如,protobuf-net 不会遍历事件/委托,并且通常不能很好地处理仅称为“对象”的事物。但是,完全支持字典和列表等关键/常见场景。

于 2012-09-20T05:43:36.907 回答