title: protobuf-net returns null when calling Deserialize
body: <p>My end goal is to use protobuf-net and GZipStream in an attempt to compress a <code>List&lt;MyCustomType&gt;</code> object to store in a varbinary(max) field in SQL Server. I'm working on unit tests to understand how everything works and fits together. </p>
  
  <p>Target .NET framework is 3.5.</p>
  
  <p>My current process is:</p>
  
  <ol>
  <li>Serialize the data with protobuf-net (good).</li>
  <li>Compress the serialized data from #1 with GZipStream (good).</li>
  <li>Convert the compressed data to a base64 string (good).</li>
  </ol>
  
  <p>At this point, the value from step #3 will be stored in a varbinary(max) field. I have no control over this. The steps resume with needing to take a base64 string and deserialize it to a concrete type.</p>
  
  <ol>
  <li>Convert a base 64 string to a <code>byte[]</code> (good).</li>
  <li>Decompress the data with GZipStream (good).</li>
  <li>Deserialize the data with protobuf-net (bad).</li>
  </ol>
  
  <p>Can someone assist with why the call to <code>Serializer.Deserialize&lt;string&gt;</code> returns <code>null</code>? I'm stuck on this one and hopefully a fresh set of eyes will help. </p>
  
  <p>FWIW, I tried another version of this using <code>List&lt;T&gt;</code> where T is a custom class I created and I <code>Deserialize&lt;&gt;</code> still returns null.</p>
  
  <p>FWIW 2, data.txt is a 4MB plaintext file residing on my C:.</p>
  
  <pre><code>    [Test]
      public void ForStackOverflow()
      {
          string data = "hi, my name is...";
          //string data = File.ReadAllText(@"C:\Temp\data.txt");
  
          string serializedBase64;
  
          using (MemoryStream protobuf = new MemoryStream())
          {
              Serializer.Serialize(protobuf, data);
  
              using (MemoryStream compressed = new MemoryStream())
              {
                  using (GZipStream gzip = new GZipStream(compressed, CompressionMode.Compress))
                  {
                      byte[] s = protobuf.ToArray();
                      gzip.Write(s, 0, s.Length);
                      gzip.Close();
                  }
  
                  serializedBase64 = Convert.ToBase64String(compressed.ToArray());
              }
          }
  
          byte[] base64byteArray = Convert.FromBase64String(serializedBase64);
  
          using (MemoryStream base64Stream = new MemoryStream(base64byteArray))
          {
              using (GZipStream gzip = new GZipStream(base64Stream, CompressionMode.Decompress))
              {
                  using (MemoryStream plainText = new MemoryStream())
                  {
                      byte[] buffer = new byte[4096];
                      int read;
  
                      while ((read = gzip.Read(buffer, 0, buffer.Length)) &gt; 0)
                      {
                          plainText.Write(buffer, 0, read);
                      }
  
                      // why does this call to Deserialize return null?
                      string deserialized = Serializer.Deserialize&lt;string&gt;(plainText);
  
                      Assert.IsNotNull(deserialized);
                      Assert.AreEqual(data, deserialized);
                  }
              }
          }
      }
  </code></pre>