C# 无法反序列化

C# 无法反序列化,c#,types,type-conversion,C#,Types,Type Conversion,我有这段代码,它还原从SQLite序列化的消息队列 public void Restore() { try { const string databaseName = @"C:\Code\C#\WcfService\WcfService\mainDB.db3"; SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0};", databaseN

我有这段代码,它还原从SQLite序列化的消息队列

public void Restore()
{
    try
    {
        const string databaseName = @"C:\Code\C#\WcfService\WcfService\mainDB.db3";
        SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0};", databaseName));
        connection.Open();
        try
        { 
            SQLiteCommand command = new SQLiteCommand("SELECT * FROM dump ORDER BY DId DESC limit 1", connection);
            SQLiteDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                var info = (byte[])reader["DBinaryData"];
                Queue<Message> deserializedData = GetDeserializedMessages(info);
                var data = MergeQueueMessage(deserializedData);
                Logger.Log(data.ToString());
            }
        }
        finally
        {
            connection.Close();
        }
    }
    catch (Exception e)
    {
        Logger.Log(e.Message);
    }
}

    public Queue<Message> GetDeserializedMessages(byte[] source)
    {
        Queue<Message> messages = null;

        using (MemoryStream memoryStream = new MemoryStream(source))
        {
            BinaryFormatter formatter = new BinaryFormatter();

            messages = (Queue<Message>)formatter.Deserialize(memoryStream);
        }
        return messages;
    }
但我有一个问题:无法从字段DBinaryData反序列化信息; 数据库中的我的表包含:

DId整数,主键 数据时间文本 DBinaryData Blob//将消息队列转储为序列化对象 尝试:

将二进制数据序列化为字节[]

i、 e


我从读取器[DBinaryData]获取信息作为对象。对象不了解ToArray方法。我认为这是您的问题,也是您试图实现的目标:但如何在reader[DBinaryData]中使用它?在GetDeserializedMessages中使用它-它与示例代码大致相同。我尝试使用Queue deserializedData=GetDeserializedMessageByte[[DBinaryData]但get异常:在完成解析之前遇到流结束
reader["DBinaryData"].ToArray();
byte[] info = reader["DBinaryData"].ToArray();