I'm currently testing in visual studio 2010. I made a client and server which both will connect through UdpClient.
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
My server sees that the object is received and tries to convert it from bytes to the object but this gives an error.
System.Runtime.Serialization.SerializationException was unhandled Message=Unable to find assembly
This seems okay because both applications are in a different namespace...
These are my methods to convert; Both the same on client and server
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);
}
}
How can I resolve this? Thanks in advance