SerializationException: End of Stream encountered before parsing was completed.

i got this error message and i dont know what it means

SerializationException: End of Stream encountered before parsing was completed.
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run () (at :0)
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize (System.Runtime.Remoting.Messaging.HeaderHandler handler, System.Runtime.Serialization.Formatters.Binary.__BinaryParser serParser, System.Boolean fCheck, System.Boolean isCrossAppDomain, System.Runtime.Remoting.Messaging.IMethodCallMessage methodCallMessage) (at :0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler, System.Boolean fCheck, System.Boolean isCrossAppDomain, System.Runtime.Remoting.Messaging.IMethodCallMessage methodCallMessage) (at :0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler, System.Boolean fCheck, System.Runtime.Remoting.Messaging.IMethodCallMessage methodCallMessage) (at :0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler, System.Boolean fCheck) (at :0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) (at :0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) (at :0)
SavingPlayer.LoadPlayer (System.Int32 saveNumber) (at Assets/Scripts/Saving Stuff/Saving Player/SavingPlayer.cs:32)
GameMenu.Loadsavefile1text () (at Assets/Scripts/Menus/GameMenu.cs:556)
GameMenu.Awake () (at Assets/Scripts/Menus/GameMenu.cs:188)

It means not all data was written to file in the first place.

1 Like

Awesome Thank you!
i was looking for this error message from 30mn XD.

This is extremely old but.
Do guys know how to know if you reach the end of the file?
I’m trying to write new data to the file but I have no idea how to know if the file reached the end.
An exception should be enough

There’s no any end when writing to file, until you reach storage device capacity. Then you will get an exception.

1 Like

Got it. You’re right I just added an Exception and it worked.
Thanks!

You should never rely your program logic on exceptions. It considered bad practice. Exception means exceptional situation where program can’t function anymore and/or can not complete operation requested by user, and nothing else. To prevent exceptions and for logic purposes you can add conditional checks along with special return values or different callbacks for async operations.

1 Like

Got it.
The issue we’re having is that we already released our game and now we added a new feature we need to save. The current save files of the player need to be updated so we go through all the data and if it returns exception on the last value it means they don’t have the latest save file format so we overwrite it with the latest one.