VS Designer: 'X' could not be set on property 'Y'

I'm currently developing some custom ASP.net server controls. Internally I often have lists, where the user (programmer) can specify a variable number of sub-controls which are consumed/managed by the parent custom server control:
public List<SomeControl> SomeControls
{
get
{
...
}

set
{
...
}
}

This kind of list is used for controls where the user (programmer) specifies something like
<mySrvCtrls:MyServerControl id="mySrvControl1" runat="server" ...>
<mySrvCtrls:SomeControl id="...1" runat="server" ... >
<mySrvCtrls:SomeControl id="...2" runat="server" ... >
<mySrvCtrls:SomeControl id="...3" runat="server" ... >
</mySrvCtrls>

They're already working, but now I'd like to add some VS designer support, since when switching to Design-View my controls throw the error
'SomeControl' could not be set on property 'SomeControls'
Apparently the problem is that collections of controls such as my "SomeControls" (dummy) property here, have to be specified as readonly, meaning to change them to something like
public List<SomeControl> SomeControls
{
get
{
...
}

}

But still, in such a case you have to pay attention to ensure in your get that you're properly instantiating the collection you're returning if it's null.
public List<SomeControl> SomeControls
{
get
{
if(_SomeControls == null)
_SomeControls = new List<SomeControl>();

return _SomeControls;
}

}

This solved my design-time error.
Kindle

Comments

0

Your ad here?