ProtoBuf-Net Error Message - "Nested or uneven lists and arrays are not supported"

The main task is to dynamically populate the Dictionary object and serialize it using Protobuf-net and send it through the client side WCF service.

@marc Can you tell me some sample code on how I can resolve the "Nested or uneven lists and arrays are not supported" error when I try to serialize using Protobuf-net.

[Serializable] [ProtoContract] public class DynamicWrapper { [ProtoMember(1)] public List<Dictionary<string, string>> Items { get; set; } public DynamicWrapper() { Items = new List<Dictionary<string, string>>(); } } public class Service1 : IService1 { public byte[] GetData(string sVisibleColumnList) { DynamicWrapper dw = new DynamicWrapper(); Dictionary<string, string> d = new Dictionary<string, string>(); d.Add("CUSIP", "123456"); dw.Items.Add(d); d = new Dictionary<string, string>(); d.Add("ISIN", "456789"); dw.Items.Add(d); var ms = new MemoryStream(); var model = ProtoBuf.Meta.RuntimeTypeModel.Default; model.Serialize(ms, dw); Serializer.Serialize <DynamicWrapper>(ms, dw); return ms.GetBuffer(); } } 
+7
c # protocol-buffers protobuf-net
source share
1 answer

You can wrap the dictionary in a separate class. Then use the list of these objects.

 [ProtoContract] public class DynamicWrapper { [ProtoMember(1)] public List<DictWrapper> Items { get; set; } public DynamicWrapper() { Items = new List<DictWrapper>(); } } [ProtoContract] public class DictWrapper { [ProtoMember(1)] public Dictionary<string, string> Dictionary { get; set; } } 
+12
source share

All Articles