c# – XML Serializer deleting player files


I’ve been getting reports from my users that sometimes the game isn’t saving. I’ve recently been provided with the game save files from one of these reports and found all the XML files were completely empty, not even the headers.

There are two instances in which these files are edited, Steam Cloud Save, and my serialization system. Below are code snippets from both systems.

Can anyone identify an issue that may cause these files to be completely wiped?

public static void Save(object data, string fileName)
{
    var serializer = new XmlSerializer(data.GetType());
    Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(Application.persistentDataPath, fileName)));
    using (var stream = new FileStream(Path.Combine(Application.persistentDataPath, fileName), FileMode.Create))
    {
        serializer.Serialize(stream, data);
    }
}
string path = Path.Combine(UnityEngine.Application.persistentDataPath, name);
if (!Directory.Exists(Path.GetDirectoryName(path))) Directory.CreateDirectory(Path.GetDirectoryName(path));
    
byte() file = SteamRemoteStorage.FileRead(name);
    
if (file != null)
{
    File.WriteAllBytes(path, file);
}