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

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

3 Answers 396 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Toby
Top achievements
Rank 1
Toby asked on 20 Aug 2009, 02:00 PM
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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] because it is an interface.

This is obvoiusly the same issue as described here :





http://www.telerik.com/community/forums/aspnet-ajax/combobox/radcombobox-load-on-demand-with-web-service.aspx

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.

thanks
Toby

3 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 21 Aug 2009, 09:02 AM
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";

new:
       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.
0
Toby
Top achievements
Rank 1
answered on 21 Aug 2009, 02:43 PM
thanks, Ill give that a go.

cheers
Toby
0
jason
Top achievements
Rank 1
answered on 17 Mar 2011, 07:13 PM
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.
Tags
TreeView
Asked by
Toby
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Toby
Top achievements
Rank 1
jason
Top achievements
Rank 1
Share this question
or