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();
    }

}

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.