I am getting exceptions in the XCeed WPF propertygrid control when there are nested collection properties. The behavior is well defined and reproducible, but very weird.
Here is an example class structure:
Public Class MyTestBigClass
Public Property FirstProperty As New List(Of MyTestLittleClass)
End Class
Public Class MyTestLittleClass
Public Property SecondProperty As New List(Of Integer)
End Class
I create a new MyTestBigClass and bind it to a PropertyGrid. I go to that form, click the FirstProperty row, which makes the Collection Editor dialog pop up. I hit "Add" a few times to create some members in the collection. Then I close the dialog. This works well enough so far, and I can confirm that the expected changes to FirstProperty actually occur.
Then I do nothing else, except click the FirstProperty row again. Now, instead of the Collection Editor coming back to show me the members I just added to that collection, I get a NullReferenceException.
Here is the weird part.
The exception does not occur if I change the second-last line to say this instead:
Public Property SecondProperty As List(Of Integer)
That gets rid of the NullReferenceException in this control, and lets me use the bound PropertyGrid just fine. But that's at the expense of problems elsewhere in the code, because SecondProperty is now most of the time null (aka Nothing in VB).
Worse, that same exception comes back if I initialize SecondProperty anywhere. Even if I make a constructor (a VB New sub) and create the object inside there, somehow having that member be non-null still makes the property grid crash itself.
What is going on? Is this an error in the control code or am I using it wrong? What's the right way to fix it?
Found out this bug lies inside the Xceed PropertyGrid control. Fixed in the paid version released as of 6/5/2017. Release notes for version 3.4.17280.14430 say in part:
In PropertyGrid, opening a CollectionControl editor will no longer crash when the items of the Collection contains List properties.