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 880423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:05:43+00:00 2026-05-15T12:05:43+00:00

In VS2010, control properties won’t get serialized despite the ShouldSerializeFoo method, with the DesignerSerializationVisibility.Visible/Content

  • 0

In VS2010, control properties won’t get serialized despite the ShouldSerializeFoo method, with the DesignerSerializationVisibility.Visible/Content as well.

Here’s the code:

class Class1 : UserControl {
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public string Foo {
        get; set;
    }
    public bool ShouldSerializeFoo() {
        return true;
    }
    public Class1() {
        Foo = "dupa";
    }
}

However, the designer doesn’t generate anything for this property:

        // 
        // class11
        // 
        this.class11.Location = new System.Drawing.Point(224, 262);
        this.class11.Name = "class11";
        this.class11.Size = new System.Drawing.Size(150, 150);
        this.class11.TabIndex = 2;
        this.class11.Load += new System.EventHandler(this.class11_Load);
  • 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-15T12:05:44+00:00Added an answer on May 15, 2026 at 12:05 pm

    You’re mixing serialization schemes. The designer serialization (which is what DesignerSerializationVisibility is for) has nothing to do with the instance serialization mechanism (which is what ShouldSerializeXXX functions, among many other things, deal with).

    DesignerSerializationVisibility.Content doesn’t make much sense for a string (or any other immutable type). The designer can view a property’s serialization as three types:

    • None – it never serializes anything about the property
    • Visible – it will serialize the actual value of the property
    • Content – it will serialize the property values of the value of the property.

    By default, a property is considered Visible. I realize that my definition of Content might be a little confusing. What I mean by that is like this:

    public class MyControl : Control
    {
        public class SomeOptions
        {
            public string Option1 { get; set; }
            public string Option2 { get; set; }
        }
    
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public SomeOptions Options { get; private set; }
    
        public string Foo { get; set; }
    }
    

    Now, when this class is serialized by the designer, it will look something like this:

    // myControl1
    this.myControl1.Foo = "value";
    this.myControl1.Options.Option1 = "option1";
    this.myControl1.Options.Option2 = "option2";
    

    This should hopefully make more sense; marking a property as Content signifies that, rather than serializing the actual value of the property (in this case, it would be an instance of SomeOptions), it should serialize the property values of that value instead.

    So, back to your question, that’s why you don’t want Content for a string property. Because strings are immutable, there’s nothing for the designer to serialize. Either mark it as Visible or leave the attribute off entirely (since that’s the default).

    While it’s possible to provide custom direction to the designer as to whether or not you want to serialize a particular property, it’s a pretty involved (and nasty) process. The easy way, though, is to use the DefaultValue attribute on the property. If whether or not the property should be serialized can be determined by comparing its value to a constant (in other words, it’s not dependent upon anything else at runtime, like the value of another property), you can decorate the property like this:

    [DefaultValue("foo")]
    public string Foo { get; set; }
    

    If the designer then sees that the value of Foo is equal to "foo", then it won’t serialize the property at all.

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

Sidebar

Related Questions

I am using VS2010, working on a WinForms application that uses the ReportViewer control
I'm using VS2010. The projects that I'm working on use different source control providers,
I'm using VS2010, C#, ASP.NET, I've inserted Ajax Control Toolkit Tab Container which works
I've been using VS2010 and I want to use some type of source control.
Where in VS2010 can I find a horizontal separator control, as can be found
My goal is to display the control DateTimePicker and MonthCalender from VS2010 in English
I have read that the viewstate in asp.net stores the values of control properties
What is the WPF control that VS2010 uses for the code editor? Some time
I'm working on a custom control for Silverlight 4 in VS2010 and Expression Blend
I was trying to add Web user control in Class Library in VS2010. is

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.