Visual Studio Designer continues to try to initialize the Collection property

I created a UserControl called CatalogBrowser that has a ListedFamilies property that exposes the currently listed Family objects in the control. Here is the code for the property.

 public List<Family> ListedFamilies { get { List<Family> returnList = new List<Family>(); foreach (Object obj in this.familyObjectListView.Objects) { returnList.Add((Family)obj); } return returnList; } set { this.familyObjectListView.ClearObjects(); this.familyObjectListView.Objects = value; } } 

Now in the form where I use this control, I constantly have a problem with Visual Studio adding the following line to the form designer file.

 this.catalogBrowserControl1.ListedFamilies = ((System.Collections.Generic.List<SOMLib.Family>)(resources.GetObject("catalogBrowserControl1.ListedFamilies"))); 

This causes my program to crash because I do not have (or want) a resource in my project to initialize the value of this collection property.

How can I prevent Visual Studio from automatically trying to initialize this property?

+4
source share
1 answer

One trick is to add the [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] attribute to your property.

+7
source

Source: https://habr.com/ru/post/1301066/


All Articles