ArgumentException when using ICustomTypeDescriptor

3 posts, 1 answers
  1. Thorsten
    Thorsten avatar
    8 posts
    Member since:
    Oct 2010

    Posted 06 Aug 2013 Link to this post

    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. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 09 Aug 2013 Link to this post

    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 >>
  3. Thorsten
    Thorsten avatar
    8 posts
    Member since:
    Oct 2010

    Posted 09 Aug 2013 Link to this post

    Thanks Didie,

    ValidatesOnDataErrors = "InEditMode" did the trick!

    Best regards,
    Thorsten
Back to Top