- Home /
EndOfStreamException : Failed to read past end of stream
So... finally decided to give up struggling and post a question :) I've been looking for some answers online but couldn't find anything related to this specific issue.
I've written a client-server application in unity 5.0.2 and when receiving a response for a message i'm sending (btw the message arrives fine to the server) i get an exception. The weird thing is that when i execute the same code in visual studio or the compiled executable i don't get this exception
6/20/2015 12:06:10 PM: Failed getting message: Failed to read past end of stream. 6/20/2015 12:06:10 PM: Stack trace: at System.IO.BinaryReader.FillBuffer (Int32 numBytes) [0x0005b] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/BinaryReader.cs:119 at System.IO.BinaryReader.ReadString () [0x00059] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/BinaryReader.cs:486 at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadStringIntance (System.IO.BinaryReader reader, System.Int64& objectId, System.Object& value) [0x00009] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:325 at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject (BinaryElement element, System.IO.BinaryReader reader, System.Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) [0x000b4] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:200 at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadValue (System.IO.BinaryReader reader, System.Object parentObject, Int64 parentObjectId, System.Runtime.Serialization.SerializationInfo info, System.Type valueType, System.String fieldName, System.Reflection.MemberInfo memberInfo, System.Int32[] indices) [0x00051] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:740 at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectContent (System.IO.BinaryReader reader, System.Runtime.Serialization.Formatters.Binary.TypeMetadata metadata, Int64 objectId, System.Object& objectInstance, System.Runtime.Serialization.SerializationInfo& info) [0x000ad] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:306 at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadRefTypeObjectInstance (System.IO.BinaryReader reader, System.Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) [0x00046] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:284 at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject (BinaryElement element, System.IO.BinaryReader reader, System.Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) [0x00053] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:179 at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (System.IO.BinaryReader reader) [0x00027] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:154 at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (BinaryElement elem, System.IO.BinaryReader reader, Boolean readHeaders, System.Object& result, System.Runtime.Remoting.Messaging.Header[]& headers) [0x0003f] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:110 at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) [0x00078] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:179 at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) [0x00000] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:136 at FF.Communication.MessageHandler.GetMessage () [0x00021] in FF\Assets\Source\Communication\MessageHandler.cs:62
Answer by Alonzo86 · Jun 20, 2015 at 02:37 PM
Finally found the issue. It seems as the message i was receiving was split into several parts i only got the 1st part which resulted in the above exception.
Still interesting to know why it didn't happen when i ran the same client with VS debugger.
Your answer
Follow this Question
Related Questions
Why has my BinaryFormatter stopped working? 2 Answers
EndOfStreamException : Failed to read past end of stream 1 Answer
Using BinaryFormatter for deserialization - ArgumentException: method argument length mismatch 0 Answers
Serialization from WinForms to Unity 1 Answer
Serialization\Deserialization problem 2 Answers