【发布时间】:2016-05-11 17:45:28
【问题描述】:
System.InvalidOperationException: {"无法为 SomeObject 准备序列化程序 内部异常:{"No serializer defined for type: System.Object"}
我的代码中是否会出现其他错误?我有很多类要序列化,但我首先测试更简单的类,以确保我的程序正常工作。
也非常重要:SomeObject 被其他类继承(不过,当我收到错误时,我只是在序列化这个基类)
[ProtoContract]
[ProtoInclude(10, typeof(AnotherObject))]
[ProtoInclude(11, typeof(YetAgainObject))]
public class SomeObject {
[ProtoMember(1)]
String mName = "";
[ProtoMember(2)]
String mOwner = "";
[ProtoMember(3)]
String mDesc = "";
}
[ProtoContract]
public class AnotherObject : SomeObject{
[ProtoMember(1)]
public object[] someList{ get; set: }
}
....
【问题讨论】:
-
您说您的
VObjectType设置正确。你试过单独序列化吗? -
是的,它会序列化但会引发错误。我想到了。我将编辑问题并发布我的答案,这样才有意义。
-
@Arthur Rey 我完成了我的编辑,措辞更好,我在下面回答了它。 Protobuf 网络继承层次结构没有“堆栈跟踪”,因此即使它是父类,它也会在当前正在序列化的类上引发错误。
标签: c# protocol-buffers protobuf-net