Serialization issue on iOS

From ETC Public Wiki
Jump to: navigation, search


The standard XML serialization in C# is not supported in Unity iOS.
You need to go through 3rd party serialization library, or write your own serializer.


protobuf-net v2

protocol buffers is the name of the binary serialization format used by Google for much of their data communications.
Please refer to protobuf-net for more information.


For basic usage of protobuf-net, please refer to Getting Started.


  • After download protobuf-net, go to Full/unity and copy the files in the folder to Plugins folder of your project.
  • Please add IsRequired=true to the ProtoMember attribute, for example: [ProtoMember(3,IsRequired=true)]. Otherwise protobuf will not serialize if your member is zero value.

iOS specific

The basic protobuf-net is still not working on iOS. For iOS you need more effort to set it up. please refer to here for the setup setup tutorial.

Note From v2, protobuf-net provide precompile\precompile.exe to assist you a little bit from the second step in the tutorial (building MySerializer.dll).

  • Assume all your classes to be serialized is already built as MyModel.dll (Remember to set that project to .NET 2.0).
  • Put MyModel.dll and the protobuf-net.dll you used to build MyModel.dll (Not the same dll used for precompile.exe) in the same folder, for example: C:\MyModelFolder.
  • Run precompile.exe as the following: precompile {path}\ModelName.dll -o:SerializerDllName.dll -t:SerializerTypeName, for example: precompile C:\MyModelFolder\MyModel.dll -o:MySerializer.dll -o:MySerializer


Thrift was created by facebook employees that made it open source It is now an Apache Incubator project.
Please refer to this discussion thread for more information about Thrift.

Unity Serializer

I just came across this project. It states it provide a solution for all platforms in Unity.
We don't have a chance to test it out. Please leave your comments if you took a try.
Please refer to this page for more information about Unity Serializer.