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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -