title: Invalid wire-type error in protobuf.net on a new MemoryStream
body: <p>I'm trying to parse a protobuf message received from an external service. I know that this data is a valid protobuf message, and I know I'm not accidentally mangling it before I send it to the deserializer. Here's my code:</p>
  
  <pre><code>public static T DeserializeFromBytes&lt;T&gt;(byte[] encoded)
  {
      MemoryStream stream = new MemoryStream(encoded);
      stream.SetLength(encoded.Length);
      stream.Capacity = encoded.Length;
      T decoded = (T)Serializer.Deserialize&lt;T&gt;(stream);
      stream.Close();
      return decoded;
  }
  </code></pre>
  
  <p>and I'm calling this method like this:</p>
  
  <pre><code>MercuryReply header = ProtobufUtils.DeserializeFromBytes&lt;MercuryReply&gt;(Convert.FromBase64String(metadata[0]));
  </code></pre>
  
  <p><code>metadata[0]</code> is a base64 string that includes a protobuf message. A sample looks something like this:</p>
  
  <blockquote>
    <p>CjRobTovL21ldGFkYXRhL2FsYnVtL2M1MzU3MTA0M2U4ODQ3YjRhODc1YzVlNmZiNmNiZTdmEhp2bmQuc3BvdGlmeS9tZXRhZGF0YS1hbGJ1bSCQAzIYCgpNRC1WZXJzaW9uEgoxMzcwMzc5NTA1Mg8KBk1DLVRUTBIFNjk2MDQyGQoPTUMtQ2FjaGUtUG9saWN5EgZwdWJsaWMyDwoHTUMtRVRhZxIELD8q+Q==</p>
  </blockquote>
  
  <p>Now, when I run the program, I get an Invalid wire-type error when deserializing. I can't see any reason why this would be happening. Is there something obvious here that I missed?</p>