Why is design-time serialization failure occurring for a child control of a panel located in a custom user control?

StackOverflow https://stackoverflow.com/questions/22669959

Question

After breaking down all possible causes of the issue, I have arrived with the following situation. I have a custom user control containing a panel and a control (button, label etc...) within this panel. I have also created public read only properties for the panel as well as the child control of the panel. Each of these properties has their DesignerSerializationVisibility attribute set to Content. When configured this way no code is serialized for the child control of the panel when the custom user control is used on a form. Upon building the control, the child control either disappears or experiences an incomplete rendering at design-time. If I change either the panel or its child control’s DesignerSerializationVisibility to visible, everything serializes and renders correctly. However, this then prevents me from being able to provide the end user with the ability to adjust either the panel or child controls property values. This one truly has me stumped!

UPDATE:

After getting home and performing the same steps on my development VM (also a fresh installation of VS2013) there are no issues. I am very confused at why this issue would be occurring on my work computer and not another. Any ideas are greatly appreciated as the mystery deepens...

Public Class ExampleUserControl
  Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.

  End Sub
<Browsable(True), _
EditorBrowsable(EditorBrowsableState.Always), _
Category("Appearance"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public ReadOnly Property LeftPanel As Panel
    Get
        Return Me.ExampleLeftPanel
    End Get
End Property
<Browsable(True), _
EditorBrowsable(EditorBrowsableState.Always), _
Category("Control"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public ReadOnly Property LeftPanelButton As Button
    Get
        Return Me.ExampleLeftButton
    End Get
End Property
<Browsable(True), _
EditorBrowsable(EditorBrowsableState.Always), _
Category("Appearance"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public ReadOnly Property RightPanel As Panel
    Get
        Return Me.ExampleRightPanel
    End Get
End Property
<Browsable(True), _
EditorBrowsable(EditorBrowsableState.Always), _
Category("Control"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public ReadOnly Property RightPanelButton As Button
    Get
        Return Me.ExampleRightButton
    End Get
End Property
End Class
Was it helpful?

Solution

I'm still not sure why this issue was occurring. However, after moving the custom user control into my control library (a separate .dll), all is working as expected. I suspect it was a glitch in the timing when compiling. Possibly it was trying to build the controls and serialize the code at the same time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top