title: UserControl collection not marked as serializable
body: <p>I must be missing something really obvious.  I'm quite new to C# but have been programming in C/C++ for years, so sorry if it IS something blindingly obvious ;)</p>
  
  <p><strong>[See Edit for newer problems]</strong></p>
  
  <p>I'm trying to create a node containing UserControl.  I have the Control appearing in the WinForm designer and I can add nodes to it.  However when I try and run the code I get the following error:</p>
  
  <blockquote>
    <p>Code generation for property 'Nodes' failed.  Error was: 'Type
    App.Node' in Assembly 'App, version=1.0.0.0, Culture=neutral,
    PublicKeyToken=null' is not marked as serializable.</p>
  </blockquote>
  
  <p>and then none of the nodes I added show up.</p>
  
  <p>This is beginning to drive me mad as, as far as I can see, it IS marked as serializable.</p>
  
  <p>The node is defined as follows:</p>
  
  <pre><code>[Serializable]
  public class Node : MarshalByRefObject
  {
      public Node()
      {
      }
  
      public Node( String text )
      {
          this.Text       = text;
          this.Checked    = false;
          this.Complete   = false;
      }
  
      public String       Text        { get; set; }
      public bool         Checked     { get; set; }
      public bool         Complete    { get; set; }
      public bool         Selected    { get; set; }
  };
  </code></pre>
  
  <p>I then define a "Collection" as follows:</p>
  
  <pre><code>[Serializable]
  public class NodeCollection : List&lt; Node &gt;
  {
      public NodeCollection() :
          base()
      {
      }
  };
  </code></pre>
  
  <p>Both the collection and the node itself have the "Serializable" attribute set as you can see.</p>
  
  <p>The Nodes property mentioned in the error is defined as follows</p>
  
  <pre><code>    private NodeCollection      mNodes  = new NodeCollection();
  
      [Category( "Behavior" )]
      [Description( "Nodes" )]
      public NodeCollection Nodes
      { 
          get
          {
              return mNodes;
          }
      }
  </code></pre>
  
  <p>So has anyone got any idea whats I'm doing wrong here?</p>
  
  <p><strong>Edit:</strong> In response to Archeg's comments this is my UserControl:</p>
  
  <pre><code>public partial class Control : UserControl
  {
      public Control()
      {
          InitializeComponent();
      }
  
      protected override void OnPaint( PaintEventArgs pe )
      {
          Graphics graph  = pe.Graphics;
  
          int rowHeight   = Font.Height + 2;
  
          if ( Nodes != null )
          {
              int yPos    = 0;
              foreach( Node node in this.Nodes )
              {
                  // Calculate my various bounding boxes.
                  Rectangle nodeBounds    = new Rectangle( Bounds.Left, yPos, Bounds.Width, rowHeight );
                  Rectangle lightBounds   = new Rectangle( Bounds.Right - Font.Height, yPos, rowHeight, rowHeight );
                  Rectangle spannerBounds = new Rectangle( lightBounds.Left - Font.Height, yPos, rowHeight, rowHeight );
                  Rectangle checkBoxBound = new Rectangle( 32, yPos, rowHeight, rowHeight );
                  Rectangle textBounds    = new Rectangle( checkBoxBound.Right, yPos, Bounds.Width - (rowHeight * 2) - checkBoxBound.Right, rowHeight );
  
                  // Draw selection box.
                  Brush textColour    = Brushes.Black;
                  if ( node.Selected )
                  {
                      graph.FillRectangle( Brushes.Blue, nodeBounds );
                      textColour      = Brushes.Yellow;
                  }
  
                  // Draw node text.
                  graph.DrawString( node.Text, Font, textColour, textBounds );
  
                  // Draw Red/Green light
                  Image[] lightImages = new Image[] { CompleteLightImage, InCompleteLightImage };
                  Image lightImage    = lightImages[node.Complete ? 1 : 0];
                  if ( lightImage != null )
                  {
                      graph.DrawImage( lightImage, lightBounds );
                  }
  
                  // Draw Spanner Icon
                  if ( SettingsImage != null )
                  {
                      graph.DrawImage( SettingsImage, spannerBounds );
                  }
                  // Draw check box.
                  VisualStyleRenderer renderer    = null;
                  VisualStyleElement  ve          = node.Checked ? VisualStyleElement.Button.CheckBox.CheckedPressed : VisualStyleElement.Button.CheckBox.CheckedNormal;
                  if (VisualStyleRenderer.IsElementDefined( ve ))
                  {
                      renderer = new VisualStyleRenderer( ve );
                  }
  
                  if ( renderer != null )
                  {
                      renderer.DrawBackground( graph, checkBoxBound );
                  }
                  else
                  {
                      ControlPaint.DrawCheckBox( graph, checkBoxBound, node.Checked ? ButtonState.Checked : ButtonState.Normal );
                  }
                  yPos    += Font.Height;
              }
          }
      }
  
      private NodeCollection      mNodes  = new NodeCollection();
  
      [Category( "Behavior" )]
      [Description( "Nodes" )]
      [DesignerSerializationVisibility( DesignerSerializationVisibility.Content )]
      [MergableProperty( false )]
      [Bindable( false )]
      public NodeCollection Nodes
      { 
          get
          {
              return mNodes;
          }
      }
  
      public Image CompleteLightImage         { get; set; }
      public Image InCompleteLightImage       { get; set; }
      public Image SettingsImage              { get; set; }
  }
  </code></pre>
  
  <p>I have made some modifications since I originally posted generally relating to the "DesignerSerializationVisibility" attribute which has helped but I am now getting the following build error:</p>
  
  <blockquote>
    <p>error MSB3103: Invalid Resx file. Could not load type App.Node, App,
    Version=1.0.0.0, Culture=neutral, PublicKeyToken=null which is used in
    the .RESX file.  Ensure that the necessary references have been added
    to your project.</p>
  </blockquote>
  
  <p><strong>Edit 2</strong>: Its worth noting that my problems only occur when I add a bunch of Nodes in the designer then I get the above Resx error.  If I add the nodes manually from code then it all works as I'd expect ...</p>