简体   繁体   中英

Error when serializing dataset with protobuf-net

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);
    }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM