c# - SerializationException: End of Stream encountered before parsing was completed -


this inherited code fails can not figure out why.

using(networkstream stream = client.getstream()) {     binaryformatter formatter = new binaryformatter();     formatter.serialize(stream, message_);     if(responsehandler_ != null) {         message response = (message) formatter.deserialize(stream); // <-- fails here         responsehandler_(response, stream);        } } 

i have googled death. have tried seeking suggestions networkstream can not seek.

edit: doesn't fail. on occasion. appreciated.

in such case i'd suggest copying networkstream memorystream, can seek - can find examples here.

with memorystream, can reset stream's location after serialized

using(var ms = new memorystream(stream) {     binaryformatter formatter = new binaryformatter();     formatter.serialize(ms , message_);     if(responsehandler_ != null) {         ms.location = 0;         message response = (message) formatter.deserialize(ms);          responsehandler_(response, ms);        } } 

Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -