我成功序列化了以下类的实例,但是当我在收到以下错误消息后立即尝试反序列化时" Invalid field in source data: 0"
:
我不知道它指的是什么,因为我直接在下面找到了。我刚刚将 protobuf-net 版本更新为 2.00.614(运行时版本:2.0.50727)。
知道我是否可能忽略了一些微不足道的事情吗?
[ProtoContract]
public class TimeSeriesProperties
{
[ProtoMember(1)]
public string TimeSeriesName { get; private set; }
[ProtoMember(2)]
public string FileName { get; private set; }
[ProtoMember(3)]
public string TemplateName { get; private set; }
[ProtoMember(4)]
public int PacketLength { get; private set; }
[ProtoMember(5)]
public long FileSizeBytes { get; set; }
[ProtoMember(6)]
public long NumberRecords { get; set; }
[ProtoMember(7)]
public DateTime DateTimeStart { get; set; }
[ProtoMember(8)]
public DateTime DateTimeEnd { get; set; }
public TimeSeriesProperties()
{
}
public TimeSeriesProperties(string timeSeriesName, string fileName, string templateName, int PacketLength)
{
this.TimeSeriesName = timeSeriesName;
this.FileName = fileName;
this.TemplateName = templateName;
this.PacketLength = PacketLength;
}
}
public static byte[] Serialize_ProtoBuf<T>(T serializeThis)
{
using (var stream = new MemoryStream())
{
ProtoBuf.Serializer.Serialize<T>(stream, serializeThis);
return stream.GetBuffer();
}
}
public static T Deserialize_ProtoBuf<T>(byte[] byteArray)
{
using (var stream = new MemoryStream(byteArray))
{
return ProtoBuf.Serializer.Deserialize<T>(stream);
}
}