Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

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

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

  1. Josh1994

    Josh1994

    Joined:
    Mar 26, 2016
    Posts:
    21
    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):
    1.  
    2. //Code removed as problem now solved
    3.  
    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

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,571
    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

    Rs

    Joined:
    Aug 14, 2012
    Posts:
    39
    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.