ControlCollection does not contain a constructor that takes 0 arguments

Summary

You get this error message when adding controls to a custom control in ASPX: CS1729: 'System.Web.UI.ControlCollection' does not contain a constructor that takes 0 arguments

Solution: Make the ControlCollection property readonly. For example:

public ControlCollection Rows { get; private set; }

Background

In ASP.NET you can make your own controls and initialize them using XML in the ASPX page:

<atl:LinkTable runat="server">
    <Rows>
        <asp:HyperLink runat="server" NavigateUrl="~/Hello.aspx">Hello</asp:HyperLink>
        <asp:HyperLink runat="server" NavigateUrl="~/World.aspx">World</asp:HyperLink>
    </Rows>
</atl:LinkTable>

The contents of Rows are converted to a control collection and passed to the LinkTable. The LinkTable looks like this:

[ParseChildren(typeof(Control), DefaultProperty = "Rows", ChildrenAsProperties = true)]
public class LinkTable : CompositeControl
{
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public ControlCollection Rows { get; private set; }
    ...
}

If you have a publicly settable ControlCollection, .NET will try to create a new ControlCollection. Because ControlCollection does not have a default constructor, it will fail with this error message:

CS1729: 'System.Web.UI.ControlCollection' does not contain a constructor that takes 0 arguments

To solve this, make sure you have private set on your ControlCollection property.