Endless Loop in WinForms Code, after trying to add TapPage to the Controlslist of a Form
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 20h 23m
- Merged PRs (30d)
- 103
Description
* .NET Core Version:
Any/All Tests from 3.0 to 6.0
* Have you experienced this same bug with .NET Framework?:
Yes
**Problem description:**
When you create a System.Windows.Forms.TabPage and try to add it to the Controls-List of a Form, then it trows an error on Add, but still (half) addes the TabPage to the Controls-List.
This by itself isn't a Problem, but if you for any reason try to remove it from the Controls-List again, then it will generate a entless loop.
This can also happen if remove any other control from the control-list.
The Reason seems to be that the TapPage is in the Control list (while it shouldn't be) but has no Parent.
**Expected behavior:**
At the very least no endless loop
**Minimal repro:**
Create a new VB.Net Project and add 2 Buttons.
Add this Code:
` Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim tp As System.Windows.Forms.TabPage
tp = New TabPage
Try
Me.Controls.Add(tp)
Catch ex As Exception
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MsgBox("Controls: " & Me.Controls.Count)
Me.Controls.Clear()
MsgBox("Controls: " & Me.Controls.Count)
End Sub`
Click the First Button, and then the 2. Button.
With the Current .Net FW + .Net Core you will get the First MsgBox, but not the secound.
Contributor guide
Assessment
This issue has not been assessed yet.