title: SerializationException when deserializing
body: <p>This code deserialize object from SQLite. I'm get serialized object from DBinaryData (BLOB) field. But get System.Runtime.Serialization.SerializationException: end of stream encountered before parsing was completed. How to fix this?</p>
  
  <pre><code>    public void Dump()
      {
          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("INSERT into 'dump' ('DTime', 'DBinaryData') VALUES ('" + DateTime.Now.ToString() + "', '" + GetSerializedMessages() + "')", connection);
                  command.ExecuteNonQuery();
              }
              finally
              {
                  connection.Close();
              }
          }
          catch (Exception e)
          {
              Logger.Log(e.Message);
          }
      }
  
      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())
                  {
                       Queue&lt;Message&gt; deserializedData = GetDeserializedMessages((byte[])reader["DBinaryData"]);
                       var data = MergeQueueMessage(deserializedData);
                       Logger.Log(data.ToString());
                  }
              }
              finally
              {
                  connection.Close();
              }
          }
          catch (Exception e)
          {
              Logger.Log(e.Message);
          }
      }
  
      public byte[] GetSerializedMessages()
      {
          byte[] result = null;
  
          MemoryStream memoryStream = new MemoryStream();
          BinaryFormatter formatter = new BinaryFormatter();
  
          try
          {
              lock (MessageQueue.Instance.Messages)
              {
                  formatter.Serialize(memoryStream, MessageQueue.Instance.Messages);
              }
              result = new byte[memoryStream.GetBuffer().Length];
              memoryStream.GetBuffer().CopyTo(result, 0);
          }
          catch (SerializationException e)
          {
              Logger.Log("Failed to serialize. Reason: " + e.Message);
          }
          finally
          {
              memoryStream.Close();
          }
          return result;
      }
  
      public Queue&lt;Message&gt; GetDeserializedMessages(byte[] source)
      {
          Queue&lt;Message&gt; messages = null;
          using (MemoryStream memoryStream = new MemoryStream(source))
          {
              BinaryFormatter formatter = new BinaryFormatter();
              messages = (Queue&lt;Message&gt;)formatter.Deserialize(memoryStream);
          }
          return messages;
      }
  
      private IEnumerable&lt;Message&gt; MergeQueueMessage(Queue&lt;Message&gt; source)
      {
          IEnumerable&lt;Message&gt; result = MessageQueue.Instance.Messages.Union(source, new EqualityComparator());
          return result;
      }
  </code></pre>