Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

"serializationStream supports seeking, but it s length is 0"

Discussion in 'Scripting' started by Josh1994, Mar 28, 2016.

  1. Josh1994


    Mar 26, 2016
    I am trying to create a simple Save and Load function, the Save function saves the value of 'totalDisplacement' if it is closer to 0 than the currently stored 'totalDisplacement', if this is true, the new 'high score' is saved and a message is outputted to the user.

    Code (csharp):
    2. //Code removed as problem now solved
    However, when I run, i'm getting one huge error:
    SerializationException: serializationStream supports seeking, but its length is 0
    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:155)
    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:136)
    Initialization.Load () (at Assets/Scripts/Initialization.cs:251)
    Initialization.Start () (at Assets/Scripts/Initialization.cs:31)

    I have commented in the code snippets what lines the last 2 errors are referring to, but cannot figure out what is wrong with them, or what any of the other errors are trying to say, does anyone have any ideas?
    Last edited: Apr 25, 2016
  2. karl_jones


    Unity Technologies

    May 5, 2015
    Looks like you are trying to load an empty file. If you don't serialize the data then when you call deserialize it has nothing to read and so throws the error. Instead of saving an empty file why not only create the file if you are serializing, then if the file exists you know it has data.
  3. Rs


    Aug 14, 2012
    This problem can also arise from accidentally or intentionally serializing/deserializing null arrays.
    Using Assert.IsNotNull before storing an array and just after loading it can quickly clear the table from this potential cause.