Can I serialize an object (containing members: Dictionary, list ... etc) in Mono and deserialize it in MS.NET or vice versa using protobuf-net?

I have a server running on MS.NET and a client on Mono (this is the Unity3D engine), and when I try to use BinaryFormatter (). A deserialize object like this:

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

the client side cannot find / load types: dictionary, list ... The same “client code” running under MS.NET works well, i.e. There are no exceptions during deserialization.

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

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

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

+4
source share
1 answer

Yes, a tool for external serialization, such as protobuf-net, would allow this — indeed, after you serialized between platforms (from C ++ to java to python to .net), framework versions do not present much of a problem.

So yes: the data serialized in protobuf-net to mono / unity is fully compatible when loaded into .NET. However, it should be noted that BinaryFormatter and protobuf-net are not direct 1: 1 equivalents - each has slightly different features and behavior. For example, protobuf-net does not host events / delegates and usually does not play well with things known only as an “object”. However, key / general scenarios, such as a dictionary and a list, are fully supported.

+2
source

Source: https://habr.com/ru/post/1435168/


All Articles