使用 protobuf-net 序列化数据集时出错
我正在尝试使用 protobuf-net 序列化数据集,但出现以下错误:
未处理的异常: System.InvalidOperationException:否 合适的默认数据集编码 成立。在 ProtoBuf.Serializer.ThrowNoEncoder(数据格式 格式,类型 valueType) at ProtoBuf.Property.PropertyFactory.CreateProperty[T](类型 类型、数据格式&格式, MemberSerializationOptions 选项)
在 ProtoBuf.Property.PropertyFactory.Create[T](成员信息 会员)在 ProtoBuf.Serializer`1.Build()
下面是正在使用的代码
[ProtoContract]
public class Packet
{
[ProtoMember(1)]
public DataSet Data { get; set; }
[ProtoMember(2)]
public string Name { get; set; }
[ProtoMember(3)]
public string Description { get; set; }
}
using (var fs = new FileStream("test0.txt", FileMode.Create))
{
Serializer.Serialize(fs, packet);
Console.WriteLine("Total bytes with protobuf-net = " + fs.Length);
}
I am trying to use protobuf-net to serialize a dataset but getting the below error:
Unhandled Exception:
System.InvalidOperationException: No
suitable Default DataSet encoding
found. at
ProtoBuf.Serializer.ThrowNoEncoder(DataFormat
format, Type valueType) at
ProtoBuf.Property.PropertyFactory.CreateProperty[T](Type
type, DataFormat& format,
MemberSerializationOptions options)
at
ProtoBuf.Property.PropertyFactory.Create[T](MemberInfo
member) at
ProtoBuf.Serializer`1.Build()
Below is the code being used
[ProtoContract]
public class Packet
{
[ProtoMember(1)]
public DataSet Data { get; set; }
[ProtoMember(2)]
public string Name { get; set; }
[ProtoMember(3)]
public string Description { get; set; }
}
using (var fs = new FileStream("test0.txt", FileMode.Create))
{
Serializer.Serialize(fs, packet);
Console.WriteLine("Total bytes with protobuf-net = " + fs.Length);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DataSet
并不是真正的数据契约,并且“v1”中没有受支持的实现(代码可作为预构建的 dll)。不过,我在“v2”这里玩了一些 这可能是有趣的,包括一系列用于比较/决策的指标。DataSet
is not really a data-contract, and there is no supported implementation in "v1" (the code available as pre-built dll). I have, however, done some playing in "v2" here that may be of interest, including a range of metrics for comparison / decision-making.