title: How to make a User control property of type Collection<MyClass> editable in Form Designer?
body: <p>Today at work, I stumbled upon a problem that was driving me nuts.</p>
  
  <p>Basically my goal is this:</p>
  
  <p>I have a <code>UserControl1</code>, with a field of the type <code>Collection&lt;Class1&gt;</code> and a corresponding property <code>Collection&lt;Class1&gt; Prop</code>. Like this:</p>
  
  <pre><code>public class UserControl1 : UserControl
  {
      private Collection&lt;Class1> field = null;
      // later changed to:
      //private Collection&lt;Class1> field = new Collection&lt;Class1>();
      [Category("Data")]
      [DefaultValue(null)]
      [Description("asdf")]
      public Collection&lt;Class1> prop
      {
          get { return field; }
          set { field = value; }
      }
  }</code></pre>
  
  <pre><code>// later added:
  //[Serializable]
  public class Class1
  {
      private bool booltest; public bool Booltest { get...set...}
      private int inttest; public int Inttest { get...set...}
  }</code></pre>
  
  <p><b>If you already know what I screwed up: no need to read the rest.</b> I am going to describe what exactly I did.</p>
  
  <p>Now I put the <code>UserControl</code> onto a random Form and change the <code>Prop</code> property. A generic "Collection Editor" appears, like the one used for the columns and groups in a listview control. I can enter data as expected. However, when I click OK, the data is gone.</p>
  
  <p>It took me over hour to figure out that I actually have to instantiate my field: <code>private Collection&lt;MyClass&gt; field = new Collection&lt;MyClass&gt;();</code>. Very good, only that the designer entered superspazzing mode. Cascading nightmare error message that can be reduced to: "You must put <code>[Serializable]</code> before your <code>Class1</code>." After doing that I could actually put my <code>UserControl1</code> on the Form again.</p>
  
  <p>But that only works once. When opening the designer of the Form where I use the <code>UserControl1</code> after editing something, it gives me an error:</p>
  
  <p><code>Object of type 'userctltest.Class1[]' cannot be converted to type 'userctltest.Class1[]'.</code></p>
  
  <p>Well. The Error List says:</p>
  
  <p><code>Warning: ResX file Object of type 'userctltest.Class1[]' cannot be converted to type 'userctltest.Class1[]'. Line 134, position 5. cannot be parsed.</code></p>
  
  <p>The designer tries to fetch the Property's data from the resx file. Removing the resx file "solves" that exactly once.</p>
  
  <p>The Form can now be displayed again, with my <code>UserControl1</code>. The Collection property <em>is</em> editable, and it is being saved. It actually works. Once. Whenever I change something and then try to open the Form's designer again, the above error occurs again. I can delete the resx file, but that will of course also delete my data.</p>
  
  <p>Relevant resources that helped me so far (among a ton of not so helpful search results):</p>
  
  <p><a href="http://www.codeproject.com/Answers/190675/Usercontrol-with-custom-class-property#answer1" rel="noreferrer">http://www.codeproject.com/Answers/190675/Usercontrol-with-custom-class-property#answer1</a><br>
  <a href="http://www.codeproject.com/KB/cs/propertyeditor.aspx" rel="noreferrer">http://www.codeproject.com/KB/cs/propertyeditor.aspx</a><br>
  <a href="http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=94" rel="noreferrer">http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=94</a><br>
  <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iserializable.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iserializable.aspx</a><br></p>
  
  <p>(I also tried implementing ISerializable and overriding GetObjectData with</p>
  
  <p><code>{ info.AddValue("testbool", testbool); info.AddValue("testint", testint); }</code></p>
  
  <p>didn't help either (I also tried the property names instead of the field names))</p>
  
  <p>Sorry for writing this like a bad horror novel btw.</p>