我有这个班级
[global::System.Serializable, global::ProtoBuf.ProtoContract(Name=@"MarketDataEntry")]
public partial class MarketDataEntry : global::ProtoBuf.IExtensible
{
// some other properties
private float _EntryPrice;
[global::ProtoBuf.ProtoMember(270, IsRequired = true, Name=@"EntryPrice", DataFormat = global::ProtoBuf.DataFormat.FixedSize)]
public float EntryPrice
{
get { return _EntryPrice; }
set { _EntryPrice = value; }
}
}
这是按预期工作的。我为EntryPrice属性将类型从float更改为十进制,现在我在此行上收到Exception消息
Serializer.Serialize(stream, toSerialize);
异常消息说
具有继承的结构或类
不支持IExtensible
错误信息本身令人困惑,因为我没有做任何改动但是浮动到十进制。这种异常消息可以改变原因吗?我应该检查什么来了解问题的来源?
我在.net 4.0上使用protobuf-net v.2.0.0.664
修改
关于Marc的评论,MarketDataEntry是另一个protocontract的基类。
[Serializable]
[ProtoContract]
public sealed class MarketData : ProtobufMarketData, IEntity
{
[ProtoMember(1)]
public long Id { get; set; }
[ProtoMember(2)]
public DateTime TransformTime { get; set; }
[ProtoMember(3)]
public DateTime CreationTime { get; set; }
[ProtoMember(4)]
public DateTime ConsumtionTime { get; set; }
[ProtoMember(5)]
public int FailedToBeConsumedCounter { get; set; }
}
编辑2
所以实际上被序列化的是MarketData的实例,它继承自ProtobufMarketData,而ProtobufMarketData又包含List类型的属性,所以我认为这就是问题所抵抗的地方。 MarketDataEntry对象列表,包含十进制属性。
[global::System.Serializable, global::ProtoBuf.ProtoContract(Name=@"ProtoBufMarketData")]
[ProtoBuf.ProtoInclude(10000, typeof(MarketData))]
public partial class ProtoBufMarketData : global::ProtoBuf.IExtensible
{
public ProtoBufMarketData() {}
private readonly global::System.Collections.Generic.List<CoreX.Shared.Entities.MarketDataDefs.MarketDataEntry> _MarketDataEntries = new global::System.Collections.Generic.List<CoreX.Shared.Entities.MarketDataDefs.MarketDataEntry>();
[global::ProtoBuf.ProtoMember(10004, Name = @"MarketDataEntries", DataFormat = global::ProtoBuf.DataFormat.Default)]
public global::System.Collections.Generic.List<CoreX.Shared.Entities.MarketDataDefs.MarketDataEntry> MarketDataEntries
{
get { return _MarketDataEntries; }
}
}