title: Sending objects with UdpClient C#
body: <p>I'm currently testing in visual studio 2010. I made a client and server which both will connect through UdpClient.</p>
  
  <p>I want to send an object from the client to the server. I have two methods to convert the object to bytes and to convert it to an object. Now, when I test my application I can't convert it back to an object once received on the server</p>
  
  <p>My server sees that the object is received and tries to convert it from bytes to the object but this gives an error.</p>
  
  <pre><code>System.Runtime.Serialization.SerializationException was unhandled   Message=Unable to find assembly
  </code></pre>
  
  <p>This seems okay because both applications are in a different namespace...</p>
  
  <p>These are my methods to convert; Both the same on client and server</p>
  
  <pre><code>public byte[] ToBytes() {
          using (MemoryStream stream = new MemoryStream()) {
              BinaryFormatter formatter = new BinaryFormatter();
              formatter.Serialize(stream, this);
  
              stream.Position = 0;
  
              byte[] byteRij = new byte[1024];
  
              stream.Read(byteRij, 0, (int)stream.Length);
  
              return byteRij;
          }
      }
  
      public static Datagram ToDatagram(byte[] rij) {
          using (MemoryStream stream = new MemoryStream()) {
              stream.Write(rij, 0, rij.Length);
  
              stream.Position = 0;
  
              BinaryFormatter formatter = new BinaryFormatter();
              return (Datagram)formatter.Deserialize(stream);
          }
      }
  </code></pre>
  
  <p>How can I resolve this?
  Thanks in advance</p>