I have a program that takes an object, turns it into an array of bytes and then sends it to another program using sockets (a la http://www.java2s.com/Tutorial/CSharp/0580__Network/Catalog0580__Network.htm Socket Client & Socket Server GUI). My problem is that when the object arrives at the second program, I cannot turn the byte[] back into an object because it recognises it as Server.Object, not Client.Object.
The code I am using to convert it to byte array and back is:
// Convert an object to a byte array
private byte[] ObjectToByteArray(Object obj)
{
if(obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
// Convert a byte array to an Object
private Object ByteArrayToObject(byte[] arrBytes)
{
MemoryStream memStream = new MemoryStream();
BinaryFormatter binForm = new BinaryFormatter();
memStream.Write(arrBytes, 0, arrBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);
Object obj = (Object) binForm.Deserialize(memStream);
return obj;
}
Here is the error message:
http://i90.photobucket.com/albums/k279/rickyoswaldiow/error.jpg
I read somwhere about sharing the class as a resource before I had this issue, but I've lost the site and cannot find it.
Does anyone know how I can either solve this problem, or maybe know another method of sending an object between two apps?