Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6579135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:51:38+00:00 2026-05-25T15:51:38+00:00

Today at work, I stumbled upon a problem that was driving me nuts. Basically

  • 0

Today at work, I stumbled upon a problem that was driving me nuts.

Basically my goal is this:

I have a UserControl1, with a field of the type Collection<Class1> and a corresponding property Collection<Class1> Prop. Like this:

public class UserControl1 : UserControl
{
    private Collection<Class1> field = null;
    // later changed to:
    //private Collection<Class1> field = new Collection<Class1>();
    [Category("Data")]
    [DefaultValue(null)]
    [Description("asdf")]
    public Collection<Class1> prop
    {
        get { return field; }
        set { field = value; }
    }
}
// later added:
//[Serializable]
public class Class1
{
    private bool booltest; public bool Booltest { get...set...}
    private int inttest; public int Inttest { get...set...}
}

If you already know what I screwed up: no need to read the rest. I am going to describe what exactly I did.

Now I put the UserControl onto a random Form and change the Prop 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.

It took me over hour to figure out that I actually have to instantiate my field: private Collection<MyClass> field = new Collection<MyClass>();. Very good, only that the designer entered superspazzing mode. Cascading nightmare error message that can be reduced to: “You must put [Serializable] before your Class1.” After doing that I could actually put my UserControl1 on the Form again.

But that only works once. When opening the designer of the Form where I use the UserControl1 after editing something, it gives me an error:

Object of type 'userctltest.Class1[]' cannot be converted to type 'userctltest.Class1[]'.

Well. The Error List says:

Warning: ResX file Object of type 'userctltest.Class1[]' cannot be converted to type 'userctltest.Class1[]'. Line 134, position 5. cannot be parsed.

The designer tries to fetch the Property’s data from the resx file. Removing the resx file “solves” that exactly once.

The Form can now be displayed again, with my UserControl1. The Collection property is 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.

Relevant resources that helped me so far (among a ton of not so helpful search results):

http://www.codeproject.com/Answers/190675/Usercontrol-with-custom-class-property#answer1
http://www.codeproject.com/KB/cs/propertyeditor.aspx
http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=94
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iserializable.aspx

(I also tried implementing ISerializable and overriding GetObjectData with

{ info.AddValue("testbool", testbool); info.AddValue("testint", testint); }

didn’t help either (I also tried the property names instead of the field names))

Sorry for writing this like a bad horror novel btw.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:51:39+00:00Added an answer on May 25, 2026 at 3:51 pm

    What you want is a design time support with CodeDom serialization. You do not need SerializableAttribute or ISerializable, those are for binary serialization.
    Since you want to serialize the collection, you must tell the designer to serialize it as such. That is done with the DesignerSerializationVisibiliby attribute – value of Content tells the designer to serialize property contents rather than property itself. Contents of the property should of course be CodeDom serializable, which simple classes with simple properties are by default.

    So if you change your UserControl1 class like this:

    public class UserControl1 : UserControl
    {
        private Collection<Class1> field = new Collection<Class1>();
    
        [Category("Data")]
        [Description("asdf")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public Collection<Class1> prop
        {
            get { return field; }
        }
    }
    

    … it should do the trick. Oh and collection properties are usually not writeable, although that is not mandatory. But serializer expects the collection property to be initialized, that is why you had to add initialization for the field.
    Another note, if you do not want that your property is marked with bold in the property editor, you can specify a more complex “default value” through a special method ShouldSerializePropertyName, which can even be private. Like so:

    private bool ShouldSerializeprop() 
    {
        return (field.Count > 0);
    }
    

    Now your property will only be bold when it is not empty. But I digress, this was not a question 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem today at work wherein I have a BindingGroup that
Problem This question actually came up at work today. We are planning an experiment
I noticed today that delete will not work in chrome when this popup blocker
I have some code that used to work. But I today when I try
Today I have encountered a problem that required me to determine the maximum index
Today i am faced with a problem that the company i work for is
Today at work someone tried to convince me that: {$obj->getTableInfo()} is fine for smarty/mvc/templating
I came across some javascript at work today that used jQuery to fetch two
I ran into an interesting problem at work today. I got a request to
I work in an asp.net shop, and I heard today that the bottleneck on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.