为protobuf-net生成序列化程序集失败

时间:2012-08-10 05:33:17

标签: c# serialization protobuf-net precompile

我正在尝试使用precompile.exe工具生成可在Windows Phone 7程序中使用的序列化程序集。我使用的数据模型继承 - 并且作为.NET 4.0程序(序列化工作)运行得很好。但是,在尝试生成序列化程序集时,我收到错误:

Adding Program.Serialization.MessagePeer...
A type can only participate in one inheritance hierarchy
at ProtoBuf.Meta.MetaType.SetBaseType(MetaType baseType) in c:\Dev\protobuf-net\protobuf-net\Meta\MetaType.cs:line 138
at ProtoBuf.Meta.MetaType.AddSubType(Int32 fieldNumber, Type derivedType, DataFormat dataFormat) in c:\Dev\protobuf-net\protobuf-net\Meta\MetaType.cs:line 125
at ProtoBuf.Meta.MetaType.ApplyDefaultBehaviour() in c:\Dev\protobuf-net\protobuf-net\Meta\MetaType.cs:line 553
at ProtoBuf.Meta.RuntimeTypeModel.Add(Type type, Boolean applyDefaultBehaviour) in C:\Dev\protobuf-net\protobuf-net\Meta\RuntimeTypeModel.cs:line 494
at ProtoBuf.Precompile.PreCompileContext.Execute() in c:\Dev\protobuf-net\precompile\Program.cs:line 340
at ProtoBuf.Precompile.Program.Main(String[] args) in c:\Dev\protobuf-net\precompile\Program.cs:line 33

我已经能够使用更简单的数据模型重现问题:

[ProtoContract]
[ProtoInclude(2, typeof(Bar))]
public abstract class Foo
{
    [ProtoMember(1)]
    public int Value { get; set; }
}

[ProtoContract]
public class Bar : Foo
{
    [ProtoMember(2)]
    public string Name { get; set; }
}

我尝试使用来自http://code.google.com/p/protobuf-net/的r284 ad 2485版本的protobuf。

precompile.exe的命令行也很简单:

D:\Projects\Program\Precompile>precompile
   "..\SerializerGen\bin\Debug\SerializerGen.dll"
   -o:MySerialization.dll
   -t:MyProgram.Serialization.PeerMessageSerializer

这是protobuf-net中的已知问题,还是我做错了什么?

1 个答案:

答案 0 :(得分:1)

嗯; System.Reflection和IKVM.Reflection报告继承属性的方式略有不同,即预编译器(使用IKVM.Reflection)看到继承 ProtoIncludeAttribute加上2(而不是1)ProtoContractAttribute s。

这已在r571中修复