I got this error when I try to load something into the MemoryStream
. I try to send a picture (in a byte stream) through the network over a server. But every time I try to send it, it says
The stream end was reached before the processing is completed.
The line with the error is marked in the code below
namespace Model_Library
{
[Serializable]
public class Package
{
public List<object> DATA;
public int ID;
public PackageType packetType;
public Package(PackageType u_type, int u_ID)
{
DATA = new List<object>();
this.ID = u_ID;
this.packetType = u_type;
}
public Package(byte[] packetBytes)
{
using (MemoryStream ms = new MemoryStream(packetBytes))
{
BinaryFormatter bf = new BinaryFormatter();
Package p = (Package)bf.Deserialize(ms); //Here is the error
ID = p.ID;
DATA = p.DATA;
packetType = p.packetType;
}
}
public byte[] toBytes()
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, this);
byte[] bytes = ms.ToArray();
ms.Close();
return bytes;
}
}
public enum PackageType
{
connect,
login,
registration,
friends,
message,
message_confirmation,
load_history,
search_friends,
add_friend
}
}