c# - 使用 protobuf 序列化 ConcurrentQueue

标签 c# .net serialization protocol-buffers protobuf-net

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

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

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

最佳答案

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

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

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

关于c# - 使用 protobuf 序列化 ConcurrentQueue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31004975/

相关文章:

c# - 在没有实现的情况下设置属性(类型接口(interface))

c++ - 易于使用的可扩展序列化/编码?

c# - 如何从 C# 中的剪贴板历史记录中获取所有数据的列表?

c# - 清空 ListView

.net - JSON.net 不包括 EmitDefaultValue 为 false 的空属性

C# 6 命名空间作为来自强类型命名空间引用的字符串

c# - 如何使用 MongoDB C# 序列化程序序列化值类型?

ruby-on-rails - 事件模型序列化不适用于 api 版本控制

c# - 将 DataTable 批量复制到 MySQL(类似于 System.Data.SqlClient.SqlBulkCopy)

c# - 检查给定路径的文件或文件夹是否存在