Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

Why is the code created by the Design-Time Serializer incomplete?

I am having a problem with a custom control I created in Visual Studio 2005. After the control is added to a Form, the created Initializer code is incomplete and I have to finish it by hand.

One of my properties is a class that implements IList. When the control is serialized each item in the list is serialized correctly. But when the AddRange code is created the object name is missing.

Example:

ToolBar as new MyToolBar
Bar=New MyBar
Button1=New MyButton
Button2=New MyButton
Button1.Text="Button1"
Button2.Text="Button2"

AddRange(New Button() {Button1,Button2})
AddRange(New MyBar() {Bar})

The last two lines need to be:

Bar.Buttons.AddRange(New Button() {Button1,Button2})
ToolBar.Bars.AddRange(New MyBar() {Bar})

Try marking your property (of type IList) with DesignerSerializationVisibility.Content. Also, make sure you new up an IList implementation in your getter. The designer probably doesn't know how to serialize it, since it doesn't know what to new up.

Generating incorrect code (as you showed) is a bug though, and has been fixed since the last preview build. The behavior you should see when the designer doesn't have enough information is that the property will simply not be serialized.



Page view counter