title: c# binary serialization "unexpected binary element: 225"
body: <p>I am trying to save my custom class using binary serialization in c#.  I have the serialization working fine (as far as I can tell, I get no errors) but when I try to deserialize it I get the following error:</p>
  
  <pre><code>SerializationException: Unexpected binary element: 255
  </code></pre>
  
  <p>Does anybody got ideas as to what could be causing this?  I'm using C# with the Unity game engine.</p>
  
  <p>EDIT:</p>
  
  <p>Here's the code, it's inside the class for my editor window.</p>
  
  <pre><code>public static LevelMetaData LoadAllLevels()
  {
      string filepath = Path.Combine(Application.dataPath, "Levels/meta.dat");
  
      BinaryFormatter serializer = new BinaryFormatter();
  
      if (File.Exists(filepath))
      {
          using (StreamReader sr = new StreamReader(filepath))
          {
              return (LevelMetaData)serializer.Deserialize(sr.BaseStream);
          }
      }
      else
      {
          LevelMetaData temp = new LevelMetaData();
  
          using (StreamWriter sw = new StreamWriter(filepath))
          {
              serializer.Serialize(sw.BaseStream, temp);
          }
          return temp;
      }
  }
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <p>Here's the LevelMetaData class:</p>
  
  <pre><code>[Serializable]
  public class LevelMetaData
  {
      public LevelMetaData()
      {
          keys = new List&lt;string&gt;();
          data = new List&lt;LevelController&gt;();
      }
  
      public LevelController this[string key]
      {
          get
          {
              if (keys.Contains(key))
                  return data[keys.IndexOf(key)];
              else
                  throw new KeyNotFoundException("Level with key \"" + key + "\"not found.");
          }
      }
  
      public void Add(string key, LevelController level)
      {
          if (!keys.Contains(key))
          {
              keys.Add(key);
              data.Add(level);
          }
      }
  
      public bool Contains(string key)
      {
          return keys.Contains(key);
      }
  
      public List&lt;string&gt; keys;
      public List&lt;LevelController&gt; data;
  }
  </code></pre>