没有为protobuf-net中的System.Version定义序列化程序

and*_*y.e 6 protobuf-net c#-4.0

在更新到最新的protobuf-net(2.0.0.601)后,我现在在尝试序列化System.Version类型的值时遇到异常.

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

这曾经在2.0.0.480中正常工作,没有做任何特殊的事情.

是否有可能让它在新版本中运行,或者是我回滚到旧版本的唯一选择?

(我还需要序列化/反序列化与旧的protobuf-net版本向后兼容.)

Mar*_*ell 4

我怀疑这与AllowParseableTypes有关 - 即它是否寻找静态Parse方法作为后备。如果我记得的话,这不能在默认模型上启用,但我想我会在下一次部署中删除该限制。但现在:

var model = TypeModel.Create();
model.AllowParseableTypes = true;
Run Code Online (Sandbox Code Playgroud)

然后存储模型(并重用它),并使用 model.Serialize/model.Deserialize。

如果我更改此默认模型限制,则只需:

RuntimeTypeModel.Default.AllowParseableTypes = true;
Run Code Online (Sandbox Code Playgroud)