I have a user control.
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public List<Person> People
{
get
{
return new List<Person>();
}
set
{
throw new NotImplementedException();
}
}
}
If I drag this control onto a Form I get a serialization error. The error changes depending on if I am dragging the control for the first time, deleting the control or whatever. The constant is that if I make Person serializeable then the error goes away. Why does the error occur when dropping an element onto a form? What is the typical fix?
Visual studio will actually do some designer serialization in order to display the UserControl. Since the Person object is not serializable, you get the error. You can either make it serializable or mark the property so the design time serialization will ignore it (see below).
You can mark the Property as
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]so it doesnt call the property while trying to setup the control in the designer.