Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No serializer defined for System.Version in protobuf-net

After updating to the latest protobuf-net (2.0.0.601) I now get an exception when trying to serialize a value of type System.Version.

[ProtoContract(SkipConstructor=true)]   
public class ServerLoginInfo
{
    [ProtoMember(1)]
    public Version ServerVersion { get; set; }
}

This used to work fine in 2.0.0.480 without doing anything special.

Is it possible to get it working in the new version or is my only option to rollback to the old version?

(I also need the serialization/deserialization to be backwards compatible with the old protobuf-net version.)

like image 697
andy.e Avatar asked Nov 09 '12 18:11

andy.e


1 Answers

I suspect this relates to AllowParseableTypes - i.e. whether it looks for a static Parse method as a fallback. If i remember, this can't be enabled on the default model, but I think I'll remove that restriction in the next deploy. But for now:

var model = TypeModel.Create();
model.AllowParseableTypes = true;

Then store model (and reuse it), and use model.Serialize/model.Deserialize.

If I change this default-model restriction, then just:

RuntimeTypeModel.Default.AllowParseableTypes = true;
like image 87
Marc Gravell Avatar answered Oct 23 '22 16:10

Marc Gravell