title: serialize/deserialize a list of objects using BinaryFormatter
body: <p>I know there were already many discussions on that topic, like this one:</p>
  
  <p><a href="https://stackoverflow.com/questions/5017274/binaryformatter-and-deserialization-complex-objects">BinaryFormatter and Deserialization Complex objects</a></p>
  
  <p>but this looks awfully complicated. What I'm looking for is an easier way to serialize and deserialize a generic List of objects into/from one file. This is what I've tried:</p>
  
  <pre><code>    public void SaveFile(string fileName)
      {
          List&lt;object&gt; objects = new List&lt;object&gt;();
  
          // Add all tree nodes
          objects.Add(treeView.Nodes.Cast&lt;TreeNode&gt;().ToList());
  
          // Add dictionary (Type: Dictionary&lt;int, Tuple&lt;List&lt;string&gt;, List&lt;string&gt;&gt;&gt;)
          objects.Add(dictionary);
  
          using(Stream file = File.Open(fileName, FileMode.Create))
          {
              BinaryFormatter bf = new BinaryFormatter();
              bf.Serialize(file, objects);
          }
      }
  
      public void LoadFile(string fileName)
      {
          ClearAll();
          using(Stream file = File.Open(fileName, FileMode.Open))
          {
              BinaryFormatter bf = new BinaryFormatter();
  
              object obj = bf.Deserialize(file);
  
              // Error: ArgumentNullException in System.Core.dll
              TreeNode[] nodeList = (obj as IEnumerable&lt;TreeNode&gt;).ToArray();
  
              treeView.Nodes.AddRange(nodeList);
  
              dictionary = obj as Dictionary&lt;int, Tuple&lt;List&lt;string&gt;, List&lt;string&gt;&gt;&gt;;
  
          }
      }
  </code></pre>
  
  <p>The serialization works, but the deserialization fails with an ArgumentNullException. Does anyone know how to pull the dictionary and the tree nodes out and cast them back, may be with a different approach, but also nice and simple? Thanks!</p>