title: C#: Why would an object that implements Serializable wouldn't be possible to serialize?
body: <p>I'm running a desktop application and when I reach this line:</p>
  
  <pre><code>serializer.Serialize(new StringWriter(sb), value);
  </code></pre>
  
  <p>It's throws the following error:</p>
  
  <pre><code>There was an error generating the XML document.
  </code></pre>
  
  <p>This is the code:</p>
  
  <pre><code>public static string Serialize(object value)
      {
          var serializer = new XmlSerializer(value.GetType());
          var sb = new StringBuilder();
          serializer.Serialize(new StringWriter(sb), value);
          return sb.ToString();
      }
  </code></pre>
  
  <p>When I debug I see this in the Watch section:</p>
  
  <pre><code>    value.GetType().IsSerializable  true    bool
  </code></pre>
  
  <p>I'm setting this before declaring <em>values</em>'s class:</p>
  
  <pre><code>[Serializable]
  </code></pre>
  
  <p>Thank you in advance.</p>
  
  <p><strong>Exception detail</strong></p>
  
  <pre><code>            System.InvalidOperationException was unhandled by user code
                Message="There was an error generating the XML document."
                Source="System.Xml"
                StackTrace:
                     at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
                     at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
                     at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
                     at Pacer.PIA.UI.WindowsForms.Controls.Utility.Serialize(Object value) in E:\Projects\Indexing\Main\Source\Pacer.PIA\Source\Pacer.PIA.UI.WindowsForms\Controls\Utility.cs:line 55
                     at Pacer.PIA.UI.WindowsForms.Controller.MainForm.ActionLoad..ctor(Int32[] index, Object objValue) in E:\Projects\Indexing\Main\Source\Pacer.PIA\Source\Pacer.PIA.UI.WindowsForms\Controller\MainForm\ActionAdd.cs:line 37
                     at Pacer.PIA.UI.WindowsForms.MainForm.SearchLoadByLoadNumber(String loadNumber) in E:\Projects\Indexing\Main\Source\Pacer.PIA\Source\Pacer.PIA.UI.WindowsForms\Forms\MainForm.cs:line 3530
                     at Pacer.PIA.UI.WindowsForms.MainForm.rmedtLoadNumber_KeyPress(Object sender, KeyPressEventArgs e) in E:\Projects\Indexing\Main\Source\Pacer.PIA\Source\Pacer.PIA.UI.WindowsForms\Forms\MainForm.cs:line 1244
                     at Telerik.WinControls.RadItem.OnKeyPress(KeyPressEventArgs e)
                     at Telerik.WinControls.UI.RadTextBoxElement.textBoxItem_KeyPress(Object sender, KeyPressEventArgs e)
                     at Telerik.WinControls.RadItem.OnKeyPress(KeyPressEventArgs e)
                     at Telerik.WinControls.UI.RadTextBoxItem.TextBoxControl_KeyPress(Object sender, KeyPressEventArgs e)
                     at System.Windows.Forms.Control.OnKeyPress(KeyPressEventArgs e)
                     at Telerik.WinControls.UI.RadMaskTextBox.OnKeyPress(KeyPressEventArgs e)
                     at System.Windows.Forms.Control.ProcessKeyEventArgs(Message&amp; m)
                     at System.Windows.Forms.Control.ProcessKeyMessage(Message&amp; m)
                     at System.Windows.Forms.Control.WmKeyChar(Message&amp; m)
                     at System.Windows.Forms.Control.WndProc(Message&amp; m)
                     at System.Windows.Forms.TextBoxBase.WndProc(Message&amp; m)
                     at System.Windows.Forms.TextBox.WndProc(Message&amp; m)
                     at Telerik.WinControls.UI.HostedTextBoxBase.WndProc(Message&amp; message)
                     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
                     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
                     at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
                InnerException: System.InvalidOperationException
                     Message="The type System.Drawing.Bitmap was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."
                     Source="niumy1xe"
                     StackTrace:
                          at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBELoadCollection.Write4_Image(String n, String ns, Image o, Boolean isNullable, Boolean needType)
                          at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBELoadCollection.Write5_BEDocument(String n, String ns, BEDocument o, Boolean isNullable, Boolean needType)
                          at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBELoadCollection.Write6_BERequirement(String n, String ns, BERequirement o, Boolean isNullable, Boolean needType)
                          at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBELoadCollection.Write8_BEMove(String n, String ns, BEMove o, Boolean isNullable, Boolean needType)
                          at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBELoadCollection.Write9_BELoad(String n, String ns, BELoad o, Boolean isNullable, Boolean needType)
                          at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBELoadCollection.Write10_ArrayOfBELoad(Object o)
                     InnerException:
  </code></pre>
  
  <p>The class:</p>
  
  <pre><code>    [Serializable]
  public class BELoadCollection : List&lt;BELoad&gt;, ICloneable
  {
      public BELoad FindByLoadId(string loadId)
      {
          return this.Find(load =&gt; load.LoadId.Equals(loadId));
      }
  
      public bool ExistsByLoadId(string loadId)
      {
          return this.Exists(load =&gt; load.LoadId.Equals(loadId));
      }
  
      public bool HasLoadsWithDocumentRequirementLinked
      {
  
          get
          {
              return this.Exists(load =&gt; load.HasDocumentsRequirementLinked);
          }
      }
  
      public void PrepareRequirementsToIndex()
      {
          this.ForEach(load =&gt;
          {
              load.PrepareRequirementsToIndex();
          });
  
      }
  
      public bool HasLoadsReadyToIndex
      {
  
          get
          {
              return this.Exists(load =&gt; load.HasDocumentsRequirementReadyToIndex);
          }
  
      }
  
      public BERequirementCollection GetRequirementsReadyToIndex()
      {
          BERequirementCollection beRequirementsReadyToIndex = new BERequirementCollection();
  
          this.ForEach(load =&gt; beRequirementsReadyToIndex.AddRange(load.GetRequirementsReadyToIndex()));
  
          return beRequirementsReadyToIndex;
      }
  
      #region ICloneable Members
  
      object ICloneable.Clone()
      {
          return this.Clone();
      }
  
      public BELoadCollection Clone()
      {
          BELoadCollection BELoadCollectionClone = new BELoadCollection();
  
          for (int i = 0; i &lt;= this.Count - 1; i++)
              BELoadCollectionClone.Add(this[i]);
  
          return BELoadCollectionClone;
      }
  
      #endregion
  }
  </code></pre>
  
  <p>And this is BELoad (just the fields)</p>
  
  <pre><code> public class BELoad : BEMetaData, ICloneable
  {
      //Fields
      private BEMoveCollection beMoveCollection;
  
      public string LoadId { get; set; }
      public string Description { get; set; }
      public string DocumentType { get; set; }
      public string Vendor { get; set; }
      public string VendorCityState { get; set; }
      public string State { get; set; }
      public string EquipmentPrefix { get; set; }
      public string EquipmentNumber { get; set; }
      public string Driver { get; set; }
      public string Shipper { get; set; }
      public string ShipperCityState { get; set; }
      public string BillTo { get; set; }
      public string BillToCityState { get; set; }
      public string Consignee { get; set; }
      public string ConsigneeCityState { get; set; }
      public string Stop { get; set; }
      public string StopCityState { get; set; }
      public string Container { get; set; }
  }
  </code></pre>