3
下面的测试失败,此错误:如何使用protobuf .NET序列化接口类型的成员?
"System.InvalidOperationException : No suitable Default IB encoding found."
[ProtoContract]
public class A
{
[ProtoMember(1)]
public IB B { get; set; }
}
public interface IB
{
}
[ProtoContract]
public class B : IB
{
[ProtoMember(1)]
public int SomeProperty { get; set; }
}
[TestFixture]
public class TestFixture
{
[Test]
public void Test()
{
var a = new A {B = new B()};
using (var m = new MemoryStream())
{
Serializer.Serialize(m, a);
}
}
}
我使用这个实现Protobuf.net的:
http://code.google.com/p/protobuf-net/
我错过了什么?非常感谢你。
如果我正在使用github存储库,这个限制仍然是真的吗? – James 2014-08-25 05:01:12
@james v2可以序列化许多基于接口的模型。尽管如此,它与最外层的对象仍然相似 – 2014-08-25 07:02:54