我正在尝试使用 protobuf-net 序列化数据集,但出现以下错误:
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()
下面是使用的代码
[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);
}
最佳答案
DataSet
不是真正数据协定,并且在“v1”中没有受支持的实现(可作为预构建 dll 获得的代码)。然而,我在“v2”中玩过一些游戏 here可能会感兴趣,包括一系列用于比较/决策的指标。
关于c# - 使用 protobuf-net 序列化数据集时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4742526/