Search code examples
c#collectioneditor

CollectionEditor yielding "Object does not match target type." for System.Drawing.Point


I have a custom control which has a property of type Collection<System.Drawing.Point>. When I use CollectionEditor to edit this property, the CollectionEditor window shows "Object does not match target type." for the "X" and "Y" properties. But if I use System.Drawing.PointF instead, there's no failure.

Can anyone please explain why this difference occurs?


Solution

  • The difference between Point and PointF lies indeed with PointConverter. Why this causes a problem is quite a long story, but at the end of the day it boils down to the following:

    The System.ComponentModel.ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor) implementation in System.ComponentModel.Design.CollectionEditor .CollectionEditorCollectionForm.SelectionWrapper simply returns this.

    According to the MSDN page of the aforementioned method of the ICustomTypeDescriptor interface, an implementation should

    Return(s) an object that contains the property described by the specified property descriptor.

    If I understand it correctly, in this case the implementation contradicts the documentation.

    This is based on some research of my own, so don't take it for granted. I posted a report of this issue on Microsoft Connect, so hopefully we'll know for sure in a few days. I'll report back when an answer is received.