Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 666793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:51:29+00:00 2026-05-13T23:51:29+00:00

The easiest way to explain this problem is to show you some code: Public

  • 0

The easiest way to explain this problem is to show you some code:

Public Interface IAmAnnoyed
End Interface

Public Class IAmAnnoyedCollection
    Inherits ObjectModel.Collection(Of IAmAnnoyed)
End Class

Public Class Anger
    Implements IAmAnnoyed
End Class

Public Class MyButton
    Inherits Button

Private _Annoyance As IAmAnnoyedCollection
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property Annoyance() As IAmAnnoyedCollection
    Get
        Return _Annoyance
    End Get
End Property

Private _InternalAnger As Anger
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property InternalAnger() As Anger
    Get
        Return Me._InternalAnger
    End Get
End Property

Public Sub New()
    Me._Annoyance = New IAmAnnoyedCollection
    Me._InternalAnger = New Anger
    Me._Annoyance.Add(Me._InternalAnger)
End Sub

End Class

And this is the code that the designer generates:

Private Sub InitializeComponent()
    Dim Anger1 As Anger = New Anger
    Me.MyButton1 = New MyButton
    '
    'MyButton1
    '
    Me.MyButton1.Annoyance.Add(Anger1)
    // Should be: Me.MyButton1.Annoyance.Add(Me.MyButton1.InternalAnger)
    '
    'Form1
    '
    Me.Controls.Add(Me.MyButton1)

End Sub

I’ve added a comment to the above to show how the code should have been generated. Now, if I dispense with the interface and just have a collection of Anger, then it persists correctly.

Any ideas?

Update 1

I’m sick of this. This problem was specifically about persisting an interface collection but now on further testing it doesn’t work for a normal collection. Here’s some even simpler code:

Public Class Anger
End Class

Public Class MyButton
    Inherits Button

Private _Annoyance As List(Of Anger)
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property Annoyance() As List(Of Anger)
    Get
        Return _Annoyance
    End Get
End Property

Private _InternalAnger As Anger
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property InternalAnger() As Anger
    Get
        Return Me._InternalAnger
    End Get
End Property

Public Sub New()
    Me._Annoyance = New List(Of Anger)
    Me._InternalAnger = New Anger
    Me._Annoyance.Add(Me._InternalAnger)
End Sub

End Class

The designer screws up the persistence code in the same way as the original problem.

Update 2

I’ve worked out what is going on. I wondered why sometimes it would work and not others. It boils down to the name that I give to the internal property and the collection.

If I rename the property ‘Annoyance’ to ‘WTF’, it will serialize correctly because ‘WTF’ is, alphabetically, after the name of the collection – ‘InternalAnger’.

It looks like the serializer is creating instances of objects alphabetically and needs my internal property to be created by the time it comes to create the collection.

I can fix this with a rename, but that’s a hack and I fear that writing a custom serializer is a big job – which I’ve never done before.

Any ideas?

Update 3

I’ve answered the question with a hack. I’m fairly confident in it unless MS change the way that codedom serializers the designer code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:51:29+00:00Added an answer on May 13, 2026 at 11:51 pm

    As i said in the OP, the problem boils down to the name that I give to the internal property and the collection.

    Without delving into a custom codedom serializer, the simple solution is to make sure the internal property’s name is alphabetically before any other property that will reference it.

    I do this by retaining the original property name ‘InternalProperty’, but I disable serialization and refer it to a proxy property, that is cunningly named, and is serialized.

    Private _InternalProperty
    Public ReadOnly Property InternalProperty
        Get
            Return Me._ProxyInternalProperty 
        End Get
    End Property
    
    <Browsable(False), EditorBrowsable(Never), DesignerSerializationVisibility(Content)> _
    Public ReadOnly Property _ProxyInternalProperty
        Get
            Return Me._InternalProperty
        End Get
    End Property
    

    This is a hack, but its better than renaming my property AInternalProperty. Also, the user will never see _ProxyInternalProperty because it’s hidden, and even if they did discover it, there is no danger in referencing it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.