Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProtoBuf-Net error message - "Nested or jagged lists and arrays are not supported"

The main objective is to dynamically populated the Dictionary Object and serialize it using the Protobuf-net and send it across the WCF service to the client side.

@marc Can you please tell me a code sample as to how can I resolve the error "Nested or jagged lists and arrays are not supported" when I am trying 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();
    }

}
like image 342
Ram Avatar asked Sep 25 '13 17:09

Ram


1 Answers

You can wrap your Dictionary into a separate class. Then use a list of these objects instead.

[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; }
}
like image 122
MichaelS Avatar answered Sep 23 '22 04:09

MichaelS