- Home /
Question by
jyzgo · Oct 19, 2015 at 10:43 AM ·
serializationdata storagedeserialization
How do I remove a serialized field correctly?
Hi guys,I save data with a serialized class ,now I want to remove a filed member that no more useful,but the old version has been already released,how can I prevent a exception when the new version deserialized the UserModel?
[Serializable]
public class UserModel {
// old version
Dictionary<string,int> readyToRemoveDict;
}
[Serializable]
public class UserModel {
//new version
//Dictionary<string,int> readyToRemoveDict;
}
//In gameManager ,that's how I saved it
public void SaveData()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/user.db");
bf.Serialize(file,userModel);// this is the UserModel
file.Close();
}
Comment
I would think you would need recreate all those files. Use the old version of the class to load them, then copy the data into a new version of the class, and then re-save the data to file from the new version of the class. Or, you can leave the data structure in place, and just ignore the data in that field.
Your answer
Follow this Question
Related Questions
Serialization from WinForms to Unity 1 Answer
Serialization\Deserialization problem 2 Answers
What are the pros and cons of ScriptableObjects vs. JSON for data files? 2 Answers
OnBeforeSerialize and OnAfterDeserialize order guarantees 0 Answers
Binary Serialization (In Editor) - Path Access denied / File not found 0 Answers