I have a simple registration form, that gets a string username, and a string password. Then, I create a simple instance of a class, where I save both those fields, it's called UserRegisterData, and looks like this:
[Serializable]
public class UserRegisterData
{
public string userName { get; set; }
public string userPassword { get; set; }
}
Then, I try to send this class from my client to the server. Before sending, I encode it, using this method:
public static byte[] ObjectToByteArray(UserRegisterData obj)
{
BinaryFormatter bf = new BinaryFormatter();
using (var ms = new MemoryStream())
{
bf.Serialize(ms, obj);
return ms.ToArray();
}
}
Here is my method for decoding the object:
public static object ByteArrayToObject(byte[] arrBytes)
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream ms = new MemoryStream(arrBytes);
return formatter.Deserialize(ms);
}
Then, I send it to the server, and it receives the data. However, when I try to decode that object on the sever using the method ByteArrayToObject(byte[] arrBytes), it throws an exception, and doesn't decode the data. here is the exception:
System.Runtime.Serialization.SerializationException: „Unable to find assembly 'LogInForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.”
I think the problem might be in the fact, that I am serializing and deserializing this object in different projects. Does anyone have a solution?