MS .Net Framework v1.1 Bug?

I have the following code:


PropertyDescriptorCollection myColl = myObj.GetPropertyDescriptionCollection();
PropertyDescriptor pd = myObj.GetOneOfYourPropertyDescriptors();
if (myColl.Contains(pd))
{
    myColl.Remove(pd);
}

For some reason, when it runs the line “myColl.Remove(pd);”, I get an exception thrown that says:


An unhandled exception of type ‘System.ArgumentException’ occurred in system.dll
Additional information: Source array was not long enough. Check srcIndex and length, and the array’s lower bounds.

   at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
   at System.ComponentModel.PropertyDescriptorCollection.RemoveAt(Int32 index)
   at System.ComponentModel.PropertyDescriptorCollection.Remove(PropertyDescriptor value)

If I do:

PropertyDescriptorCollection myColl = myObj.GetPropertyDescriptionCollection();

PropertyDescriptor pd = myObj.GetOneOfYourPropertyDescriptors();

bool found = false;

foreach (PropertyDescriptor currentPD in myColl)

{

  if (currentPD.Equals(pd))

  {

    found = true;

    break;

  }

}


The variable “found” ends up being true. So I know that the collection definately contains the item.  So is this a bug in the framework?  Is PropertyDescriptorCollection.Remove(…) not written correctly by Microsoft?

One thought on “MS .Net Framework v1.1 Bug?

  1. Did you ever determine a workaround for this bug? I"m about to implement by own PropertyDescriptorCollection where Remove will work. I just hope that DataBinding likes my collection. Before I go down that track it would be could to know what if any solution you found.

    Cheers,

    Andrew

Leave a Reply

Your email address will not be published. Required fields are marked *