title: Unity - InvalidCastException on Editor auto-refresh for List of object (who was valid before)
body: <p>I'm working on a project manager who define scripts who can be used by multiple of others project later (by extending some part to update them).</p>
  
  <p>I actually have:</p>
  
  <ul>
  <li>2 namespaces <strong>Foo</strong> (the manager) and <strong>Bar</strong> (the project)</li>
  <li>Both define an object <strong>Character</strong> (Bar.Character extend from Foo.Character)</li>
  <li>FooEngine is here to list Foo.Character (List)</li>
  <li>FooEngineEditor (defined on Bar namespace) is here in order to add (both Foo or Bar Character) and display Characters (and their cast)</li>
  </ul>
  
  <h2>Foo</h2>
  
  <pre><code>namespace Foo
  {
      [System.Serializable]
      public class Character
      {
          public int ID;
          public Character(int ID)
          {
              this.ID = ID;
          }
      }
  
  
      public class FooEngine : MonoBehaviour
      {
          public List&lt;Foo.Character&gt; list = new List&lt;Foo.Character&gt;();
      }
  }
  </code></pre>
  
  <h2>Bar</h2>
  
  <pre><code>namespace Bar
  {
      [System.Serializable]
      public class Character: Foo.Character
      {
          public string name;
          public MyObject(int ID, string name)
              : base (ID) {
              this.name= name;
          }
      }
  
      [CustomEditor(typeof(Foo.FooEngine))]
      public class FooEngineEditor : Editor
      {
          public override void OnInspectorGUI()
          {
              Foo.FooEngine fooEngine = (Foo.FooEngine)target;
  
              // --- Default inspector
              DrawDefaultInspector();
  
              // --- Action
  
              int countExistig = fooEngine.list.Count;
  
              GUILayout.BeginHorizontal();
              if (GUILayout.Button("Add Foo.Character"))
              {
                  fooEngine.list.Add(new Foo.Character(countExistig));
              }
              if (GUILayout.Button("Add Bar"))
              {
                  fooEngine.list.Add(new Bar.Character(countExistig, "abc"));
              }
  
              // --- Review
              for (int i = 0, l = fooEngine.list.Count; i &lt; l; i++)
              {
                  EditorGUILayout.LabelField(" - " + i + " &gt; " + fooEngine.list.GetType());
              }
          }
      }
  }
  </code></pre>
  
  <p>Everyting is working fine and I can use the Editor script in order to Add Foo.Character or Bar.Character into the same list (and casting works fine).</p>
  
  <p>But when I save code, List are re-casted into Foo.Character and will create InvalidCastException Error if I try to cast <code>Bar.Character character = (Bar.Character)fooEngine.list[0];</code></p>
  
  <p><a href="https://i.stack.imgur.com/p4jXo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p4jXo.png" alt="enter image description here"></a></p>
  
  <p>What's append and what's causing the list to be recasted ??</p>