Integer List values don't get initialized in Constructor of Class

I created a List but get a NullReferenceException whenever I try to refer to it. I have a DataManager Class (saves & loads Data) and a UserData Class (stores the fields that are needed to be saved or loaded). In the User Data Class I declare in initialize a List of integer type. The List contains the unlocked Levels and it is inititialized in the Constructor of the User Data Class.

This is the DataManager Class:

public static class DataManager
{
    public static List<int> GetUnlockedLevels()
    {
        UserData userData = Load();
        return userData.unlockedLevels; // This method returns nothing, not even null!
    }

    private static void Save(UserData data)
    {
        string path = GetDataFilePath();
        BinaryFormatter binaryFormatter = new BinaryFormatter();
        using (FileStream fileStream = File.Open(path, FileMode.OpenOrCreate))
        {
            binaryFormatter.Serialize(fileStream, data);
        }
    }

    private static UserData Load()
    {
        string path = GetDataFilePath();
        if (!File.Exists(path))
        {
            UserData userData = new UserData();
            Save(userData); 
        }
        BinaryFormatter binaryFormatter = new BinaryFormatter();
        using (FileStream fileStream = File.Open(path, FileMode.Open))
        {
            return (UserData)binaryFormatter.Deserialize(fileStream);
        }
    }

And here comes the UserData Class:

[Serializable]
public class UserData
{
    public int score;
    public List<int> unlockedLevels;
    public UserData()
    {
	score = 50;
    unlockedLevels = new List<int>();
    unlockedLevels.Add(1); //unlocked by default
    unlockedLevels.Add(2); //unlocked by default
    unlockedLevels.Add(3); //unlocked by default
    }
}

The problem is: the first method of the DataManager “GetUnlockedLevels()” returns nothing.

The weird part: I have the exact same Data Manager in another project where it works properly. In that other project, the GetUnlockedLevels-method returns “System.Collections.Generic.List´1[System.Int32]” when I return it via “Debug.Log”. But in the new project, the method returns literally nothing (not even null; the exception comes at a later point)
I am sure that I didn’t make a copy-paste-mistake. What could be the root for this error?

can you add this line in the Load method and tell me what it prints?

Debug.Log(File.ReadAllText(path));

my bet is that the file exists but is empty somehow

There is something weird. When I copy-paste your code, it tells me the unlockedlevels from parameters and unlockedlevels from constructor is not the same (not clue why). A copy paste from parameter to constructor fixes it. I don’t get why.

this works here :

[System.Serializable]
public class UserData
{
    public int score;
    public List<int> unlockedlevels = new List<int>();

    public UserData()
    {
        score = 50;
        unlockedlevels.Add(1); //unlocked by default
        unlockedlevels.Add(2); //unlocked by default
        unlockedlevels.Add(3); //unlocked by default
    }
}