title: Not marked as serializable error when serializing a class
body: <p>I am serializing an structure by using <code>BinaryFormatter</code> using this code:</p>
  
  <pre><code>private void SerializeObject(string filename, SerializableStructure objectToSerialize)
  {
      Stream stream = File.Open(filename, FileMode.Create);
      BinaryFormatter bFormatter = new BinaryFormatter();
      bFormatter.Serialize(stream, objectToSerialize);
      stream.Close();
  }
  </code></pre>
  
  <p>Which <code>objectToSerialize</code> is my structure, I'm calling this function like this:</p>
  
  <pre><code>SerializableStructure s = new SerializableStructure();
  s.NN = NN;
  s.SubNNs = SubNNs;
  s.inputs = inputs;
  SerializeObject(Application.StartupPath + "\\Save\\" + txtSave.Text + ".bin", s);
  </code></pre>
  
  <p>Which <code>SerializableStructure</code>, and Type of <code>NN</code>, <code>SubNNs</code> and inputs are serializable. (inputs contains some <code>Points</code>, <code>Rectangles</code> and generic lists).</p>
  
  <p>Now, When I run my code, I am given this error:</p>
  
  <blockquote>
    <p>Type 'MainProject.Main' in Assembly 'MainProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.</p>
  </blockquote>
  
  <p>Why I'm given this error? Main is my form, and these variables are located in my form.</p>
  
  <p>I have successfully serialized Type of <code>NN</code> with <code>MemoryStream</code> and VB.NET , But I don't know why I'm getting this error?</p>
  
  <p>Here is the definition of my structures:</p>
  
  <p>SerializableStructure:</p>
  
  <pre><code>[Serializable()]
  public class SerializableStructure
  {
      public List&lt;Inputs&gt; inputs = new List&lt;Inputs&gt;();
      public NeuralNetwork NN;
      public NeuralNetwork[] SubNNs;
  }
  </code></pre>
  
  <p>Inputs:</p>
  
  <pre><code>[Serializable()]
  public class Inputs
  {
      public string XPath { get; set; }
      public string YPath { get; set; }
      public string ImagePath { get; set; }
      public string CharName { get; set; }
      public string CharBaseName { get; set; }
      public List&lt;double&gt; x { get; set; }
      public List&lt;double&gt; y { get; set; }
      public List&lt;double&gt; DotsX { get; set; }
      public List&lt;double&gt; DotsY { get; set; }
      public List&lt;Point&gt; GravityCenters { get; set; }
      public List&lt;Rectangle&gt; Bounds { get; set; }
  
      public override string ToString()
      {
          return CharName;
      }
  
      public Inputs(string xPath, string yPath, string imagePath, string charName, string charBaseName)
      {
          XPath = xPath;
          YPath = yPath;
          ImagePath = imagePath;
          CharName = charName;
          CharBaseName = charBaseName;
          x = new List&lt;double&gt;();
          y = new List&lt;double&gt;();
          GravityCenters = new List&lt;Point&gt;();
          Bounds = new List&lt;Rectangle&gt;();
      }
  }
  </code></pre>
  
  <p>Also <code>NN</code> is very big structure(!).</p>