使用 protobuf 序列化 ConcurrentQueue

Serializing ConcurrentQueue using protobuf

我正在尝试使用 protobuf 序列化一个 ConcurrentQueue,但在反序列化对象时出现异常

Type is not expected, and no contract can be inferred: System.Collections.Concurrent.ConcurrentQueue`1[[System.Byte[], mscorlib

有办法解决吗?比如写 Protobuf 的扩展或者继承和扩展 ConcurrentQueue?

protobuf 的开发者已声明 here ConcurrentQueue<T> 不受支持,并提供了类似于 Lloyd 的建议的解决方法。添加以下代码以防 link 不再可用:

public ConcurrentQueue<int> Items {get;set;}

[ProtoMember(n)]
private int[] Items
{
    get { return Items.ToArray(); }
    set { Items = new ConcurrentQueue<int>(value); }
}