Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: SerializationException: The constructor to deserialize an object of type 'StringIntDictionary' was not found. #14

Open
YHSX88 opened this issue Feb 3, 2020 · 2 comments

Comments

@YHSX88
Copy link

YHSX88 commented Feb 3, 2020

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 'StringIntDictionary' was not found.
Rethrow as SerializationException: The constructor to deserialize an object of type 'StringIntDictionary' was not found.

image

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 info if needed.

Thank you in advance !

@szynall
Copy link

szynall commented Apr 2, 2020

@YHSX88 Had the same error. Try to override all contructors. I'm using different save method so I'm not sure this gonna work for you.


public StringStringDictionary() : base() { }

  public StringStringDictionary(IDictionary<string, string> dict) : base(dict) { }

  protected StringStringDictionary(SerializationInfo info, StreamingContext context) : base(info, context) { }

@YHSX88
Copy link
Author

YHSX88 commented Apr 2, 2020

@szynall thanks for advice .. but I switched to another solution but it will be nice, maybe someone else is using the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants