This is a migrated thread and some comments may be shown as answers.

ArgumentException when using ICustomTypeDescriptor

2 Answers 147 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thorsten
Top achievements
Rank 1
Thorsten asked on 06 Aug 2013, 12:26 PM
Hi all,

I am using a RadGridView to display a list of DataRowBase objects which implements the ICustomTypeDescriptor. When the grid starts to populate its rows I observed some "first chance" ArgumentExceptions printed out in the output window of the IDE. ("An exception (first chance) of the type "System.ArgumentException" occurred in System.ComponentModel.DataAnnotations.dll" - translated from German).
As the grid showed all my data correctly, I could probably ignore the messages - but it was very slow in doing so. So I used a hard-coded class with the same data and the same grid and this was significantly faster (and didn't throw any exceptions). (I need to use a generic approach as the application allows the user to display data of csv files and I want to utilize all features of the grid view, like filtering, sorting, grouping etc.)

I took my while to find out how to track this exception message down to its root:
The original exception message is: "The type "DataRowBase" does not contain a public property "RefDate"." (translated from German, may not be accurate)
And it seems to be thrown by some code in "GridViewVirtualizingPanel.cs".

I can't see whether this exception is thrown by the above class or somewhere deeper in the .net framework (as the message in the output window suggests, see above). But it is interesting to see that the exception is thrown only once per row, not per row and column (as all my columns are generic).

This leads to the assumption that the interface ICustomTypeDescriptor is not used properly. I found a very helpful article on how this interface is used by System.ComponentModel.TypeDescriptor in an older issue of the MSDN Magazine: MSDN Magazine: ICustomTypeDescriptor, Part 1: "... Before going straight to the metadata to get property information, TypeDescriptor first checks to see if the type being examined implements the System.ComponentModel.ICustomTypeDescriptor interface. If it does, (...), rather than using the metadata to get property information, TypeDescriptor will simply ask the object (through its ICustomTypeDescriptor.GetProperties method) which properties it supports."

I added some Debug.WriteLine's to my ICustomTypeDescriptor.GetProperties() implementation and this revealed that
a) the above exception is thrown after a first call to GetProperties() of each(!) DataRowBase instance in my list, and
b) GetProperties() is called for every displayed column of the same instance (w/o exception) [why that? An initial call should be sufficient]

My question is here: Is this a problem of the RadGridView? Or does the problem lie deeper within the framework?

Any help/suggestion is highly appreciated!

Thanks,
Thorsten

PS
I am using RadControls for WPF, Q2 2013 and WPF 4.5

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 09 Aug 2013, 01:39 PM
Hi Thorsten,

As to the "ArgumentException" in System.ComponentModel.DataAnnotations.dll (for every row(item)) - these exceptions are thrown by DataAnnotation.Validator class when item is ICustomTypeDescriptor (even with System.Data.DataRowView). Unfortunately we cannot remove them (for the default case) without a breaking change. You can remove them by setting RadGridView.ValidatesOnDataErrors = "InEditMode", then you will get such exception only when you edit and commit a row.

Does this work for you? If not, then may I ask you to isolate the issue in a demo project and send it to us via a support ticket?

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Thorsten
Top achievements
Rank 1
answered on 09 Aug 2013, 03:26 PM
Thanks Didie,

ValidatesOnDataErrors = "InEditMode" did the trick!

Best regards,
Thorsten
Tags
GridView
Asked by
Thorsten
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Thorsten
Top achievements
Rank 1
Share this question
or