Today I sat down to code a shiny new feature but instead found myself ripped into the past to work on a feature that shipped long ago. Bugs in general are never fun but revisiting a feature that you’ve long since “finished” is especially annoying. Today was no exception.
The client was receiving “Too many items in the combo box”. This seems like a fairly straightforward error. You’ve simply attempted to add too many items to the combo box right? Wrong. It has nothing to do with how many items are in the combo box.
A quick Google reveals the source of the misleading error. If the NativeAdd() method of the combo box fails for any reason it throws an OutOfMemoryException indicating a ComboBoxItemOverflow. This happens when the overriden ToString() method of the object you’re attempting to add returns a null.
The obvious fix is to ensure that any ToString() overrides never return null. And indeed that works. However, what makes this particular issue even more frustrating is the way Visual Studio seems to eat the exception.
When running the application via Visual Studio the exception is silently swallowed and the code proceeds like nothing is wrong. But when running the code outside of Visual Studio the exception is consistently thrown. That makes for a nice little bug that can easily slip through development unnoticed.
Design by Simon Fletcher.
© Copyright 2012