atikot
atikot

Reputation: 5041

Serializing ConcurrentQueue using protobuf

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?

Upvotes: 2

Views: 1040

Answers (1)

Jurgen Camilleri
Jurgen Camilleri

Reputation: 3589

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); }
}

Upvotes: 4

Related Questions