protobuf.net意外亚型 [英] protobuf.net Unexpected subtype

查看:152
本文介绍了protobuf.net意外亚型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Protobuf.net遇到这种异常在我的项目:

I'm encountering this Exception in my project using Protobuf.net:

InvalidOperationException "Unexpected sub-type: foo"

我有我送它看起来像这样一类:

I have a class which I'm sending which looks like this:

class message
{
    list<bar> listOfBars;
}

FOO继承关吧,但protobuf的似乎呛到这一点,并产生上述异常。有没有解决这个某种方式?我需要能够容纳酒吧的各个不同亚型的列表,以便更加约束类型的解决方案将是困难的/不可能的。

foo inherits off bar, However protobuf seems to choke on this and generate the exception above. Is there some way around this? I need to be able to hold all different subtypes of bar in the list, so a more type constrained solution would be difficult/impossible.

推荐答案

我可能是错了,但我认为你需要指定的继承类,子类型继承它,例如:

I may be mistaken, but I think you need to specify on the inherited class which subtypes inherit from it, for example:

[Serializable, ProtoContract, ProtoInclude(100, typeof(Foo))]
class Bar { }

[Serializable, ProtoContract]
class Foo : Bar { } // Inherits from Bar

这篇关于protobuf.net意外亚型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆