C# 在具有继承的结构或类中不支持IEExtensible
我有这门课C# 在具有继承的结构或类中不支持IEExtensible,c#,protobuf-net,C#,Protobuf Net,我有这门课 [global::System.Serializable, global::ProtoBuf.ProtoContract(Name=@"MarketDataEntry")] public partial class MarketDataEntry : global::ProtoBuf.IExtensible { // some other properties private float _EntryPrice; [global::ProtoBuf.
[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更改为decimal,现在我在这一行上得到异常消息
Serializer.Serialize(stream, toSerialize);
例外消息说
在具有继承的结构或类中不支持IEExtensible
错误消息本身令人困惑,因为我没有做任何更改,只是将浮点值改为十进制。该更改是否可以作为此异常消息的原因?我应该检查什么来了解问题的来源
我在.NET4.0上使用ProtobufNetV.2.0.0.664
编辑
关于Marc的评论,MarketDataEntry是另一个协议的基类
[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,它又包含List类型的属性,所以我认为这就是问题所在。MarketDataEntry对象的列表,其中包含decimal属性
[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; }
}
}
[global::System.Serializable,global::ProtoBuf.ProtoContract(Name=@“ProtoBufMarketData”)]
[ProtoBuf.ProtoInclude(10000,类型为(市场数据))]
公共部分类ProtoBufMarketData:global::ProtoBuf.ieextensable
{
公共ProtoBufMarketData(){}
private readonly global::System.Collections.Generic.List _MarketDataEntries=new global::System.Collections.Generic.List();
[global::ProtoBuf.ProtoMember(10004,Name=@“MarketDataEntries”,DataFormat=global::ProtoBuf.DataFormat.Default)]
公共全局::System.Collections.Generic.List MarketDataEntries
{
获取{return\u MarketDataEntries;}
}
}
这很奇怪;我会的investigate@MarcGravell谢谢,更奇怪的是,在我得到异常之后,我用Person ProtoContract创建了一个小测试项目,它具有decimal属性,并且我可以成功地序列化/反序列化Person对象。这个异常可能来自何处,我应该关注什么?在您的实际项目中,MarketDataEntry
是否可能实际上是更复杂的继承模型的一部分?在本地,我让您的类参加了一组测试,涉及(单独的)float
,double
和decimal
——它们都工作得非常好。到目前为止,我根本无法重新编程。我想知道这个问题是否与我看不到的东西有关——可能是“某些其他属性”,或者是部分类的另一部分。但代码如下所示:有效fine@MarcGravell-是的,实际上它是另一个协议的基类。我会更新帖子,这样你们就可以看到继承链了。关于你的第二个评论,我不相信它是其他属性,因为如果我恢复我的更改,并且使用类型为float的EntryPrice属性,一切都会按照预期工作。