【发布时间】:2020-10-02 09:53:26
【问题描述】:
我正在尝试使用protobuf-net 序列化现有的遗留类:
using ProtoBuf;
using System;
using System.Collections.Generic;
[ProtoContract]
public class AttributeValue {
List<IComparable> attributeValues;
[ProtoMember(1)]
public List<IComparable> Values {
get {
return this.attributeValues;
}
}
}
我得到一个例外说No serializer for type System.IComparable is available for model (default)。
查看一些示例,我发现应该在 ProtoMember 属性中添加 DynamicType = true 属性,但现在已弃用。
有没有另一种方法来序列化和反序列化具有这样声明的成员的类?
【问题讨论】:
-
我认为您应该在指定可能的具体类型时使用
ProtoInclude属性。 -
我试过了,但是
ProtoInclude属性不能用于成员,只能用于类。
标签: c# protobuf-net