We have a project which uses serialization by implementing ISerializable and using BinaryFormatter. We are moving to .net compact which do not have BinaryFormatter class. I was wondering if we can use ProtoBuf-Net. Can we instruct ProtoBuf-Net to use GetObjectData() for serialization? Specifically, I want to find out how to use Serializer.Serialize(SerializableInfo, ISerializable) function.
Added
I looked at the source code and I see that though the function
Serializer.Serialize(SerializableInfo, T t) where T is ISerializable
doesn’t use the constraint T is ISerializable at all. Why was T declared to be ISerializable?
The
ISerializablesupport exists (at the moment) as a mechanism for injecting protobuf-net into the middle of existing APIs that useBinaryFormatter– for example, you can do this to reduce the overhead of .NET remoting or (serialized) session-state. However, this still results in a pb-net BLOB in the middle of aBinaryFormatterwrapper (in particular, the bf header specifies the concrete type assembly-qualfied-name).Re the question about the constraint – that is simply to help guide usage; that API is only intended to be used as part of this injection into
BinaryFormatterviaISerializable. Otherwise it is preferred to just use theStreambased API.If you are looking at CF, then of course
BinaryFormatterceases to be useful, but theStreambased API is fine. It works on CF, but you should note that for models with lots of classes there are currently some glitches on CF caused by the overuse of generics (“missing method” or some-such). The good news is that I’m making good progress on some refactoring that ditches this, making it much more stable on the smaller frameworks.