Cannot serialize member Telerik.Web.UI.ControlItemData.Attributes

4 posts, 1 answers
  1. Toby
    Toby avatar
    59 posts
    Member since:
    Jul 2009

    Posted 20 Aug 2009 Link to this post

    I have a TreeView which is bound to a webservice which works fine. However if you go to the asmx file to see the webservice definition. You get the following error

    Cannot serialize member Telerik.Web.UI.ControlItemData.Attributes of type System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]] because it is an interface.

    This is obvoiusly the same issue as described here :

    To fix it you suggest creating a custom class type

    Is this possible as I am refering to the attributes property when returning the array of data , so creating a custom class wont make any difference.

    i.e. public IDictionary<string, object> Attributes { get; set; }

    it would be nice if the definition would display properly.

  2. Answer
    Veselin Vasilev
    Veselin Vasilev avatar
    2992 posts

    Posted 21 Aug 2009 Link to this post

    Hello Toby Moxha,

    If you define your custom class you can add as properties all the custom attributes you use, e.g.

    old: node.Attributes["address"] = "test street";

           myNodeData.Address = "test street";

    Then you can set the attribute in the OnClientNodeDataBound event.

    Please check the first approach in this help topic:
    Setting additional properties to the node in the Web Service

    Best wishes,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Toby
    Toby avatar
    59 posts
    Member since:
    Jul 2009

    Posted 21 Aug 2009 Link to this post

    thanks, Ill give that a go.

  4. jason
    jason avatar
    2 posts
    Member since:
    Jun 2010

    Posted 17 Mar 2011 Link to this post

    Using a custom data class that is serializeable is neccesary not sufficient to get around this problem.

    The problem is, some classes and interfaces in .net are serializable and some are not.  The dictionary class, the sorted list, and ienumerable are not.  Many Telerik examples use class that contain properties that are dictionaries or that return ienumerable.  Microsoft should fix the problem by enhancing more of the basic data containers and interfaces so that they are serializable but they haven't done so even in the fourth iteration of .net.  The other option is for Telerik to make descendant classes from dictionary and ienumerable that implement xml serialization.  This is that I do in my projects with this problem.  However, neither of these solutions is forthcoming so instead we will have to reply upon kludges.   

    Solution:  We will declare everything as an object.

    Here is some stripped down Telerik code:

    Public Function GetNodes(ByVal node As RadTreeNodeData, ByVal context As IDictionary) As IEnumerable
    return new RadTreeNodeData
    end function

    Problem is, RadTreeNodeData.Attributes is a dictionary which is not serializable and IEnumerable is also not serializable.  Context is also a dictionary which is not serializable.

    Just change the above code to:
    Public Function GetNodes(ByVal node As Object, ByVal context As Object) As Object
    return new RadTreeNodeData
    end function

    Problem solved.
Back to Top