Unfortunately, none of the proposed solutions solve the real source of the problem. This exception means that your deserializer tries to read from the end of a stream.
The solution is to rewind the stream to the beginning, ie. set the stream.Position = 0; before deserialization.
Also, as the comments mention, if you used a StreamWriter you need to flush it before using the stream.