0

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)

slfan
  • 8,950
  • 115
  • 65
  • 78
kliklk
  • 33
  • 1
  • 5
  • Have you checked your config file to make sure you aren't hitting a throughput limit? – Peter Gluck Aug 16 '12 at 04:40
  • What config file are you referring to? – kliklk Aug 16 '12 at 05:40
  • The app.config or web.config file that initializes your C# application. – Peter Gluck Aug 16 '12 at 05:44
  • My app.config file has nothing in it : – kliklk Aug 16 '12 at 05:50
  • 1
    That's my point. You are using the default configuration. There are limits on the amount of data that can be transferred by default and you may be hitting one of those limits. The default value for maxRequestLength is 4 MB as indicated in [this post](http://stackoverflow.com/questions/4548305/maximum-value-of-maxrequestlength) – Peter Gluck Aug 16 '12 at 06:01
  • correct? because it tells me that "The 'maxAllowedContentLength' attribute is not allowed" – kliklk Aug 16 '12 at 06:08
  • No, that is not correct. If you google maxAllowedContentLength you will find the correct usage in [this StackOverflow post](http://stackoverflow.com/questions/4022434/how-to-set-the-maxallowedcontentlength-to-500mb-while-running-on-iis7). BTW, the default for maxAllowedContentLength is 30 MB. – Peter Gluck Aug 16 '12 at 06:13
  • Thank you for the help, I did this - but still the same error :( – kliklk Aug 16 '12 at 06:49
  • Try adding this to your config file: `` – Peter Gluck Aug 16 '12 at 06:57
  • tried this too – kliklk Aug 16 '12 at 07:01
  • Tried the also didn't work any other ideias? BTW on a 3 MB file it the error was :No map for object '{0}' – kliklk Aug 16 '12 at 07:07
  • Well, you're getting a different error so that's progress. I googled your error message and [found this](http://stackoverflow.com/questions/10986296/c-cant-serialize-to-binary). That may not be your problem but it seems to indicate (as the error says) that there is a problem with your deserialization map, possibly a small typo that you're not seeing. Good luck. – Peter Gluck Aug 16 '12 at 07:13
  • It happends only on that file on other files its the original error so I think the solution is not with the new error, any ideias on what to do next, i tried to serealize with ProtoBuf but got the error "Type is not expected, and no contract can be inferred" and coudnt fined a solution that works :( – kliklk Aug 16 '12 at 07:22

0 Answers0