1

I've been getting an error during deserialization:

SerializationException: Could not find type 'System.Collections.Generic.List`1[[ExampleNamespace.ExampleClass, Assembly-CSharp, Version=0.1.6279.22118, Culture=neutral, PublicKeyToken=null]]'.

First I have serialized a custom [Serializable] class (saveStructure):

BinaryFormatter formatter = new BinaryFormatter();
FileStream file = File.Open(saveFilePath, FileMode.Open);

formatter.Serialize(file, saveStructure);
file.Close();

Which contains a few fields along with a List<ExampleClass> field. MyCustomClass is also a [Serializable] class.

It seems to serialize the structure properly, but can not read it back during deserialization:

BinaryFormatter formatter = new BinaryFormatter();
FileStream file = File.Open(saveFilePath, FileMode.Open);

SaveStructure saveStructure = (SaveStructure)formatter.Deserialize(file);
file.Close();

I am aware of XmlSerializer, however I do not want to expose the data to the users.

Thanks in advance!

Edit:

I have solved my problem by using Arrays instead of Lists, however, if someone is to offer a solution for the List problem, I'd still be grateful!

Zhafur
  • 1,626
  • 1
  • 13
  • 31
  • 3
    *"I am aware of XmlSerializer, however I do not want to expose the data to the users."* I hear this all the time as a reason why Json, Xml or PlayerPrefs should not be used. BinaryFormatter can be reversed. That's the thing. You can use [json](http://stackoverflow.com/questions/40965645/what-is-the-best-way-to-save-game-state/40966346#40966346) or xml then encrypt the string before saving. You may find [this](https://forum.unity3d.com/threads/saving-loading-with-encryption.341926/) post helpful. – Programmer Mar 11 '17 at 12:37
  • To answer your question, there are problems with `BinaryFormatter` in Unity. My first recommendation to you is to make sure that your `SaveStructure` class in declared in another file without any other class. The file it must be placed in should be like this: `SaveStructure.cs` . Don't place any other file there and don't declare that class in another existing class. If this fails then use [json](http://stackoverflow.com/questions/40965645/what-is-the-best-way-to-save-game-state/40966346#40966346) or xml. – Programmer Mar 11 '17 at 12:40

0 Answers0