- Home /
What does "SerializationException: Unexpected binary element: 116" mean?
This happened after I shrunk down my script to just one function for refreshing the saved data. The Unity Console doesn't give me any error after I saved the script. This issue shows up when I run my app in Unity. I tried to change the script execution order, but no luck either. I copied the code from my previous script; it worked fine recently.
using System.Collections;
using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public class UserInfo : MonoBehaviour {
public string _UserName;
public ArrayList SavedGamerID;
public string ServerName;
void Start(){
this.gameObject.GetComponent<DownloadAndUpLoadUserData>().DownloadLocalUserData();
RefreshSavedUserInfo();
}
public void RefreshSavedUserInfo() {
if (File.Exists(Application.persistentDataPath + "/UserInfo/UserAccount.save"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/UserInfo/UserAccount.save", FileMode.Open);
UserData data = (UserData)bf.Deserialize(file);
_UserName = data.UserName;
SavedGamerID = new ArrayList(data.GamerInfo);
file.Close();
}
}
public void SaveUserInfo() {
FileStream file;
BinaryFormatter bf = new BinaryFormatter();
file = File.Create(Application.persistentDataPath + "/UserInfo/UserAccount.save");
UserData data = new UserData();
data.UserName = _UserName;
data.GamerInfo = new ArrayList(SavedGamerID);
bf.Serialize(file, data);
RefreshSavedUserInfo();
}
}
[1]: /storage/temp/100599-capture.png
Answer by Bunny83 · Aug 24, 2017 at 03:39 PM
You most likely changed something in your "UserData" class. This will break any save you have created previously. The binary formatter stores the object in a binary format. The class need to be exactly the same. So you need to delete all previous saves you created.
btw: Why do you use an "ArrayList"? It's an untyped collection. You really should use a generic List instead.
It worked!!!! Thank you. I will go looking up for generic List
By the way, you might want want to look into Data Contract Versioning if you keep updating classes that have to be loaded from older saves.
Your answer
Follow this Question
Related Questions
High Score with player prefs confusion (JAVA) 0 Answers
Why does PlayerPrefs save to the Windows Registry? 0 Answers
PlayerPrefs.GetString not saving past values 0 Answers
Save and load system not working please help 1 Answer
How to save user levels? 0 Answers