Click here to Skip to main content
15,907,905 members
Please Sign up or sign in to vote.
2.60/5 (2 votes)
See more:
Hello there. My question is that I have Client-Server program, and I'm having a problem form recive a object form the server to the client. In the server I have serialized the object and sent it, but in the client I recive the object in the format of an byte array but I cannot convert it into a object. Can anyone help me?
Posted
Comments
CPallini 17-Apr-11 4:01am    
You should elaborate. How did the server serialize the object (please show the code)?
[no name] 17-Apr-11 6:39am    
private static byte[] ConvertToByteArray(object obj)
{
try
{
BinaryFormatter Formatador = new BinaryFormatter();
MemoryStream Stream = new MemoryStream();
Formatador.Serialize(Stream, obj);
return Stream.ToArray();
}
catch (Exception ex)
{
Console.WriteLine("Object Could Not be Converted To a Byte.");
MessageBox.Show(ex.Message);
}
return null;
}
thats de function to convert a object into a byte array and below are the function to convert a byte array into a object

private object ConvertToObject(byte[] byteArray)
{
try
{
BinaryFormatter Formatador = new BinaryFormatter();
MemoryStream stream = new MemoryStream(byteArray);
stream.Position = 0;
return (SystemInfo)Formatador.Deserialize(stream);
}
catch (Exception ex)
{
MessageBox.Show("Object Could Not be Converted To a Byte. Error message: " + ex.Message);
}
return null;
}

The function to convert to byte array works well, but now when I try to convert to a object it throw an exception saying " Can not find assembly 'Server, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null'."

sorry for the bothering...

Well I already explained what to do here[^]; it's just the reverse of the serialisation process. Since this is your object you are the only person who knows what steps are required to recreate it.
 
Share this answer
 
No, because the only answer could be "use serialization", but you're trying to say you already use it. And you are not trying to explain what's your real problem. Don't you think it's pretty difficult to provide more help in this situation?

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900