-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
needs-area-labeluntriagedThe team needs to look at this issue in the next triageThe team needs to look at this issue in the next triage
Description
.NET version
.NET 8, 10 etc.
Did it work in .NET Framework?
Yes
Did it work in any of the earlier releases of .NET Core or .NET 5+?
No response
Issue description
ComboBox.ObjectCollection.CopyTo(Array destination, int index) "leaks" the Entry objects to destination, instead of copying the actual items.
It should be InnerList[i].Item here:
Line 290 in 2f677f9
| destination.SetValue(InnerList[i], i + index); |
cf. CopyTo(object[] destination, int arrayIndex):
Line 275 in 2f677f9
| destination[i + arrayIndex] = InnerList[i].Item; |
And also for example ListBox.ObjectCollection.CopyTo(Array destination, int index):
Line 289 in 2f677f9
| destination.SetValue(InnerArray.GetItem(i), i + index); |
Steps to reproduce
This code works in .NET 4.8 but throws InvalidCastException in .NET core.
class MyItem
{
}
static void Main(string[] args)
{
var cbo = new ComboBox();
cbo.Items.Add(new MyItem());
var item1 = (MyItem)cbo.Items[0];
var arrayList = new ArrayList(cbo.Items);
var item2 = (MyItem)arrayList[0]; // <-- InvalidCastException
}
Metadata
Metadata
Assignees
Labels
needs-area-labeluntriagedThe team needs to look at this issue in the next triageThe team needs to look at this issue in the next triage