Serializing ConcurrentQueue using protobuf

1k views Asked by At

I am trying to serialize a ConcurrentQueue using protobuf , but i am getting an exception when i am deserializing the object

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

is there a way to solve it? like writing extension to Protobuf or inheriting and extending ConcurrentQueue?

1

There are 1 answers

0
Jurgen Camilleri On BEST ANSWER

The developer of protobuf has stated here that ConcurrentQueue<T> is not supported and gives a workaround similar to Lloyd's suggestion. Adding the code below in case the link is no longer available:

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

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