C# ProtoBuf网络错误消息-“;不支持嵌套或交错列表和数组";

C# ProtoBuf网络错误消息-“;不支持嵌套或交错列表和数组";,c#,protocol-buffers,protobuf-net,C#,Protocol Buffers,Protobuf Net,主要目标是动态填充Dictionary对象,并使用Protobuf网络对其进行序列化,然后通过WCF服务将其发送到客户端 @marc您能告诉我一个代码示例,当我尝试使用Protobuf net进行序列化时,如何解决“嵌套或交错列表和数组不受支持”的错误 [Serializable] [ProtoContract] public class DynamicWrapper { [ProtoMember(1)] public List<Dictionary<string,

主要目标是动态填充Dictionary对象,并使用Protobuf网络对其进行序列化,然后通过WCF服务将其发送到客户端

@marc您能告诉我一个代码示例,当我尝试使用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();
    }

}
[可序列化]
[原始合同]
公共类动态说唱机
{
[原成员(1)]
公共列表项{get;set;}
公共动态说唱者()
{
项目=新列表();
}
}
公共类服务1:IService1
{
公共字节[]GetData(字符串sVisibleColumnList)
{
DynamicWrapper dw=新的DynamicWrapper();
字典d=新字典();
d、 添加(“CUSIP”、“123456”);
dw.项目。添加(d);
d=新字典();
d、 添加(“ISIN”、“456789”);
dw.项目。添加(d);
var ms=新内存流();
var model=ProtoBuf.Meta.RuntimeTypeModel.Default;
序列化(ms、dw);
Serializer.Serialize(ms,dw);
返回ms.GetBuffer();
}
}

您可以将词典包装到单独的类中。然后使用这些对象的列表

[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; }
}
[协议]
公共类动态说唱机
{
[原成员(1)]
公共列表项{get;set;}
公共动态说唱者()
{
项目=新列表();
}
}
[原始合同]
公共类听写包装器
{
[原成员(1)]
公共字典{get;set;}
}

请注意,该对象使用不同的API序列化了两次。