Search

OutOfMemoryException - Too many items in the combo box by Gaiii

Closed
as Won't Fix Help for as Won't Fix

3
0
Sign in
to vote
Type: Bug
ID: 417533
Opened: 2/24/2009 8:12:39 AM
Access Restriction: Public
0
Workaround(s)
1
User(s) can reproduce this bug
Hi,
Couldn't find an existing KB for this issue:

I'm trying to add a couple of items to the Combobox.Items collection and I receive the error described in the title.

The reason is that each object I'm trying to add is an instance of a class that overrides the 'ToString' method and in some cases the method returns null.

The thing is, that the implementation of ComboBox.NativeAdd look like this:

private int NativeAdd(object item) {
            Debug.Assert(IsHandleCreated, "Shouldn't be calling Native methods before the handle is created.");
            int insertIndex = (int)SendMessage(NativeMethods.CB_ADDSTRING, 0, GetItemText(item));
            if (insertIndex < 0) {
                throw new OutOfMemoryException(SR.GetString(SR.ComboBoxItemOverflow));
            }
            return insertIndex;
        }

You can see that is assumes that if the item could not be added it is a memory related issue which in may case, not correct.

I'm using VS2008 SP1, .NET framework 3.5 sp1.

Cheers,
Gai.
Details (expand)
Product Language
English

Version

.NET Framework 3.5 SP1
Operating System
Windows XP Professional
Operating System Language
English
Steps to Reproduce
create a winforms project in VS with a similar code:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
MyComboboxItem item1 = new MyComboboxItem { Text = "Some text" };
MyComboboxItem item2 = new MyComboboxItem();

comboBox1.Items.Add(item1);
comboBox1.Items.Add(item2);
}
}

public class MyComboboxItem
{
public string Text { get; set; }

public override string ToString()
{
return Text;
// return Text ?? string.Empty;
}
}
Actual Results
OutOfMemoryException is thrown with the message: "Too many items in the combo box"
Expected Results
NullReferenceException?!
TAP Code (if applicable)
 
      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey. [Details]

 

File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 2/25/2009 at 9:16 PM
Thanks for your feedback on the .NET Framework!

We are able to reproduce the bug that you reported and consider rolling in a fix to this issue in next release if resources/schedule allow us.

Many customers have found it useful to discuss issues like this in the forums (http://forums.microsoft.com/msdn/default.aspx?siteid=1) where Microsoft and other members of the community can suggest workarounds.

Please keep the feedback comming.

Thanks,
UIFx Team
Posted by Microsoft on 2/25/2009 at 12:23 AM
Thanks for your feedback. We are escalating this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Sign in to post a workaround.