title: Error in deserializing a compressed string (End of Stream encountered before parsing was completed) C#
body: <p>I am encountering exception <strong>[System.Runtime.Serialization.SerializationException: End of Stream encountered before parsing was completed.]</strong> on de-serializing a string, please guide me what should I do to fix this error. </p>
  
  <pre><code>byte[] compressed;
  
  string content = "afjsklf lkjflfkldsflkfj fa fj lflkf lk kj lkj fldsjf lkflewru pjdslk jsdfi;j klnvmlvnetu iowu lknxvmln3-958u09v lsn";
  
  var compMS = new MemoryStream();
  using (var compressor = new GZipStream(compMS, CompressionMode.Compress))
  {
      new BinaryFormatter().Serialize(compressor, content);
      compressed = compMS.ToArray();
  }
  
  var decompMS = new MemoryStream(compressed);
  using (var decompressor = new GZipStream(decompMS, CompressionMode.Decompress))
  {
      BinaryFormatter bf = new BinaryFormatter();
      decompMS.Position = 0;
      string result = (string)bf.Deserialize(decompMS);
  
  }
  </code></pre>
  
  <p>I also tried to use <code>decompMS.Seek(0, SeekOrigin.Begin);</code> but exception is still there.</p>
  
  <p><a href="http://dotnetfiddle.net/PF7egd" rel="nofollow">http://dotnetfiddle.net/PF7egd</a></p>