Groups | Blog | Home
all groups > dotnet clr > august 2004 >

dotnet clr : Bug in System.ComponentModel.PropertyDescriptorCollection.RemoveAt


mns
8/25/2004 7:11:04 AM
The following program reproduces a bug in
System.ComponentModel.PropertyDescriptorCollection.RemoveAt: Removing any but
the last item of the collection generates a System.ArgumentException.

--- Start code to reproduce bug ---
<pre>
namespace PropertyDescriptorCollectionBug
{
class HasAProperty
{
public int Test1 { get { return 1; } }
public int Test2 { get { return 2; } }

static void Main(string[] args)
{
System.ComponentModel.PropertyDescriptorCollection collection =
System.ComponentModel.TypeDescriptor.GetProperties(typeof(HasAProperty));
System.Diagnostics.Debug.Assert(collection.Count == 2);

System.ComponentModel.PropertyDescriptor[] array = new
System.ComponentModel.PropertyDescriptor[collection.Count];
collection.CopyTo(array, 0);
collection = new System.ComponentModel.PropertyDescriptorCollection(array);

collection.RemoveAt(0); <b>// Throws System.ArgumentException</b>
}
}
}
</pre>
--- End code to reproduce bug ---

Examining the implementation of this function with Reflector, I come up to
this obviously untested implementation:

<pre>
public void RemoveAt(int index)
{
if (this.readOnly)
{
throw new NotSupportedException();
}
if (index < (this.propCount - 1))
{
Array.Copy(this.properties, ((int) (index + 1)),
this.properties, index, ((int) (this.propCount - index))); <b>// Should be
this.propCount - index - 1</b>
}
--this.propCount;
}
</pre>

Off by one errors... Ahhhh...

mharsh NO[at]SPAM online.microsoft.com
9/2/2004 4:00:03 PM
Thank you for taking the time to put together this bug repro case. Please use the MSDN product feedback center to report this bug. Using the MSDN
feedback center will allow you to track this bug through its lifespan and will also allow others to vote for it.

http://lab.msdn.microsoft.com/ProductFeedback

Thanks
- mike

--------------------
[quoted text, click to view]

__

This posting is provided "AS IS" with no warranties and confers no rights.

AddThis Social Bookmark Button