BUG: “Index was out of range” error message when you access a Visual Basic .NET 2002 collection object that implements IList with -1 Base
Symptoms
When you use the IList interface with a Visual Basic .NET collection object in Visual Basic .NET (2002) before you use the Insert property, you can insert elements in the list at index -1. If you insert an element at index -1, you receive the following error message when you try to read the element by using the Item property at index -1:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Resolution
The IList index has a base of -1 instead of zero. Therefore, you can insert an element at index -1 even though MSDN documentation states that the IList index is zero-based. However, you receive an error when you try to read the value from the IList at index -1.

Leave a Reply