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



我正在尝试使用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:Devprotobuf-netprotobuf-netMetaMetaType.cs:line 138
at ProtoBuf.Meta.MetaType.AddSubType(Int32 fieldNumber, Type derivedType, DataFormat dataFormat) in c:Devprotobuf-netprotobuf-netMetaMetaType.cs:line 125
at ProtoBuf.Meta.MetaType.ApplyDefaultBehaviour() in c:Devprotobuf-netprotobuf-netMetaMetaType.cs:line 553
at ProtoBuf.Meta.RuntimeTypeModel.Add(Type type, Boolean applyDefaultBehaviour) in C:Devprotobuf-netprotobuf-netMetaRuntimeTypeModel.cs:line 494
at ProtoBuf.Precompile.PreCompileContext.Execute() in c:Devprotobuf-netprecompileProgram.cs:line 340
at ProtoBuf.Precompile.Program.Main(String[] args) in c:Devprotobuf-netprecompileProgram.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/的 protobuf 的 r284 ad 2485 版本。

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

D:ProjectsProgramPrecompile>precompile
   "..SerializerGenbinDebugSerializerGen.dll"
   -o:MySerialization.dll
   -t:MyProgram.Serialization.PeerMessageSerializer

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

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

这在 r571 中已修复

最新更新