Hello! I've using SaveGameFree for some time without problems but when I changed my code to use encoding and encryption it fails to load serialized data.
I'm using the current asset store version and received the error in both Unity 2017.3.1f1 and Unity 2018.1.1f1. I'm using Windows 7 64-bits and my project is targeting Android (IL2CPP).
The error is:
SerializationException: Invalid binary format
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadRefTypeObjectInstance (System.IO.BinaryReader reader, System.Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:281)
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject (BinaryElement element, System.IO.BinaryReader reader, System.Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:179)
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (BinaryElement element, System.IO.BinaryReader reader) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:130)
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (BinaryElement elem, System.IO.BinaryReader reader, Boolean readHeaders, System.Object& result, System.Runtime.Remoting.Messaging.Header[]& headers) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:104)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:179)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:136)
BayatGames.SaveGameFree.Serializers.SaveGameBinarySerializer.Deserialize[StorageSG] (System.IO.Stream stream, System.Text.Encoding encoding) (at Assets/BayatGames/SaveGameFree/Scripts/Serializers/SaveGameBinarySerializer.cs:57)
UnityEngine.Debug:LogException(Exception)
BayatGames.SaveGameFree.Serializers.SaveGameBinarySerializer:Deserialize(Stream, Encoding) (at Assets/BayatGames/SaveGameFree/Scripts/Serializers/SaveGameBinarySerializer.cs:61)
BayatGames.SaveGameFree.SaveGame:Load(String, StorageSG, Boolean, String, ISaveGameSerializer, ISaveGameEncoder, Encoding, SaveGamePath) (at Assets/BayatGames/SaveGameFree/Scripts/SaveGame.cs:675)
BayatGames.SaveGameFree.SaveGame:Load(String, Boolean, String) (at Assets/BayatGames/SaveGameFree/Scripts/SaveGame.cs:450)
Assets.Scripts.TestSaveGameFreeEncoder:Start() (at Assets/Scripts/TestSaveGameFreeEncoder.cs:35)
Here is a test code that gives the same error I received in my actual project.
namespace Assets.Scripts
{
[System.Serializable]
public class StorageSG
{
public DateTime myDateTime;
public StorageSG()
{
myDateTime = DateTime.UtcNow;
}
}
public class TestSaveGameFreeEncoder : MonoBehaviour
{
private string _encodePassword;
private void Start()
{
_encodePassword = "12345678910abcdef12345678910abcdef";
SaveGame.DefaultEncoding = Encoding.UTF8;
SaveGame.Encode = true;
ISaveGameSerializer sgBinarySerializer = new SaveGameBinarySerializer();
SaveGame.Serializer = sgBinarySerializer;
StorageSG ssg = new StorageSG();
SaveGame.Save<StorageSG>("pizza2", ssg, _encodePassword);
StorageSG ssgLoaded = SaveGame.Load<StorageSG>("pizza2", true, _encodePassword);
Debug.Log(ssgLoaded.myDateTime.ToLocalTime().ToString());
}
}
}```
Thanks in advance.