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();
}
}
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; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With