title: Protobuf-net serialization on sockets. No parameterless constructor found ProtoException
body: <p>I have created an application where interprocess communication is done using sockets. The procedure starts when a client connects with the server that I created and sends a serialized message. This message, I serialize using Protobuf-net, using SerializeWithLengthPrefix and deserialize it using DeserializeWithLengthPrefix. The client sends messages to the server who deserializes it perfectly, but the same is not true in the case of server to client. </p>
  
  <p>The main class is BaseMessage, which is abstract.</p>
  
  <pre><code>[Serializable, ProtoContract, ProtoInclude(5001, typeof(LogonMessage))]
  abstract public class BaseMessage
  {
      public BaseMessage()
      {
  
      }
  
      abstract public int MessageType { get; }
  }
  </code></pre>
  
  <p>And LogonMessage implements the BaseMessage Class.</p>
  
  <pre><code>[Serializable, ProtoContract]
  public class LogonMessage : BaseMessage
  {
      public LogonMessage()
      {
  
      }
  
      [ProtoMember(1)]
      public string Broker { get; set; }
  
      [ProtoMember(2)]
      public int ClientType { get; set; }
  
      public override int MessageType
      {
          get { return 1; }
      }
  }
  </code></pre>
  
  <p>After the initial handshake, the client requests some service serialized with the help of protobuf-net and the local server at my end serves it by requesting data from another server on the web. This message transfer from the client to the server is done flawlessly.</p>
  
  <p>When my server receives the data from the web server,  it serializes it and sends the data to the client. But this time, when I try to deserialize the data on the client-side using the same procedure, I get the following exception:
  "No parameterless Constructor found for BaseMessage"</p>
  
  <p>I deserialize using the following line of code(this is where the exception occurs).</p>
  
  <pre><code>BaseMessage baseMessage = Serializer.DeserializeWithLengthPrefix&lt;BaseMessage&gt;(networkStream, PrefixStyle.Base128);
  </code></pre>
  
  <p>And this is how the message was serialized on the server.</p>
  
  <pre><code>Serializer.SerializeWithLengthPrefix(networkStream, baseMessage, PrefixStyle.Base128);
  </code></pre>
  
  <p>The NetworkStream used at the start of the connection between the client and server is stored in an object and that object is stored in a dictionary. I pick out the same NetworkStream from that object in the dictionary and use it to send serialized data to the client(from the server). But the above mentioned problem occurs. Any help?</p>
  
  <p>Thanks in advance...</p>