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

标签 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 和 2485 版本的 protobuf .

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

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

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

最佳答案

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

这是在 r571 中修复的

关于c# - 为 protobuf-net 生成序列化程序集失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11895998/

相关文章:

c# - WPF:不透明度和 MouseEnter 事件

java - java对象在网络传输时是否保留hashcode值

java - 序列化和反序列化同一对象并不反射(reflect)其状态的变化

c# - protobuf-net 使用 DynamicType 序列化 System.Object 抛出异常

c# - xsd 生成器到 C#/protobuf

c# - SignalR,如何验证连接 ID 是否仍处于事件状态?

c# - 如何判断默认打印机何时更改?

java - 无效类型代码 : 30 java in ObjectInputStream

c# - 动态对象序列化

c# - 我有一个 IDictionaryEnumerator 设置为 ResourceReader.GetEnumerator,如何获取所有资源的列表?