Share via


Can you be your own parent (And no, this is not a KUOW Weekday discussion)?

No you can't.

Or can you?

No, you can't.

Just ran into this bug in my code:

I was getting an annoying StackOverflow, but it was hard to figure out why because the debugger was not willing to show me the originating code - just the recurring call to the Parent property.

Once I used a "Hit Count" breakpoint and found the code where the call came from, it became much easier:

 // Save/Download button.
m_openDownloadButton = new Button();
m_openDownloadButton.
Controls.Add(m_openDownloadButton);
m_openDownloadButton.Text = "Open/Download";

At some point I added a line containing "m_openDownloadButton." and did not complete whatever it was I wanted to write there. The code compiles fine, but tries to add a control as its own child, causing the SO.