【发布时间】:2012-08-10 05:33:17
【问题描述】:
我正在尝试使用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/ 的 protobuf 的 r284 和 2485 版本。
precompile.exe 的命令行也很简单:
D:\Projects\Program\Precompile>precompile
"..\SerializerGen\bin\Debug\SerializerGen.dll"
-o:MySerialization.dll
-t:MyProgram.Serialization.PeerMessageSerializer
这是 protobuf-net 中的一个已知问题,还是我做错了什么?
【问题讨论】:
-
有趣;我有一个repro并将调查。作为旁注,该模型不可能工作 -
Foo上有一个重复的字段 1 - 在复制/粘贴过程中是否有问题? (这不会影响您看到的错误,但它让我怀疑“并且作为 .NET 4.0 程序运行得很好”) -
糟糕,这是剪切/粘贴错误,我会修复示例。出于好奇,问题是什么?我短暂地尝试过调试它,但后来意识到我对逻辑的理解不够,没有更多地研究它以提出快速(和正确)的修复。
标签: c# serialization protobuf-net precompile