c# - deserializing large object

646 views Asked by At

I have a chat that has a file sharing system that I built by slightly modifying monotorrent.

When a user shares a file the client serializes the Monotorrent.common.torrent object (represents a .torrent file) and sends it to the server inside of another object and the server deserialize it. This works only when the file that the user shares is small(about less than 1 MB). When its larger the server gives the following exeption:

Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization.

This is my deserialization code:

public CommendData ByteArrayToCommendData(byte[] arrBytes)
{
    using (MemoryStream memStream = new MemoryStream(arrBytes))
    {
        BinaryFormatter binForm = new BinaryFormatter();
        memStream.Seek(0, SeekOrigin.Begin);
        CommendData obj = (CommendData)binForm.Deserialize(memStream);
        return obj;
    }
}

(CommendData contains the Monotorrent.common.torrent object in this instance)

0

There are 0 answers