SerializableDictionary icon indicating copy to clipboard operation
SerializableDictionary copied to clipboard

SerializationException: The constructor to deserialize an object of type 'StringIntSerializableDictionary' was not found.

Open YHSX88 opened this issue 5 years ago • 0 comments

Hi

I'm trying to use the library to save file to disk. I'm serializing object that has 2 dictionaries using your library. I can save them without no errors but when i try open the file and deserialize I get this error from Unity 2019.2.19f1 on Win 10.

Error: SerializationException: The constructor to deserialize an object of type 'StringIntSerializableDictionary' was not found. Rethrow as SerializationException: The constructor to deserialize an object of type 'StringIntSerializableDictionary' was not found.

Here is the code for saving and opening the file:

Save to Disk code: public void saveGameToDisk (string saveGameName, thxdss gameObjectToSave) {

Debug.Log ("Start Writing File");

try 
{
    BinaryFormatter bf = new BinaryFormatter ();

    FileStream file = File.Create (Application.persistentDataPath + "/" + saveGameName + ".dat");

    gameObjectToSave.initDB = true;

    bf.Serialize (file, gameObjectToSave);

    file.Close ();
} 
catch (Exception ex) 
{
    Debug.Log (ex.Message);
}

}

======================================================== Restore from Disk

public thxdss getLocalSaveGame(string saveGameName) {

    thxdss localData = new thxdss();

    if (File.Exists(Application.persistentDataPath + "/" + saveGameName + ".xxx"))
    {
        Debug.Log ("there is file...");

        FileStream file = File.Open(Application.persistentDataPath + "/" + saveGameName + ".xxx", FileMode.Open);

        file.Position = 0;

        file.Seek(0, SeekOrigin.Begin);

        BinaryFormatter bf = new BinaryFormatter();

        localData = (thxdss)bf.Deserialize(file);

        file.Close();

        return localData ;
    }
    else
    {
        Debug.Log("No Local Save game file is found ALERT !!!");

        return null;
    }
}

I can provide more that if needed.

Thank you in advance !

YHSX88 avatar Feb 02 '20 20:02 YHSX88