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

Deserialization Problem

1 Answer 52 Views
Dock
This is a migrated thread and some comments may be shown as answers.
debett
Top achievements
Rank 1
debett asked on 15 May 2009, 05:21 PM
Dear all,

I am serializing the state of my docks using xml serializer (also tried javascriptserializer).
However, not all the values are deserialized correctly. For instance, width and height of the docks are being lost.

This is an example of the object before serialization and after deserialization:

+  [0] {"UniqueName":"5eb163f6a40aaa4e42a8b15a3c768b30db0f","DockZoneID":"ctl00_contentpane_Top","Width":"250px","Height":"250px","ExpandedHeight":"0","Top":"0px","Left":"0px","Resizable":"False","Closed":"False","Collapsed":"False","Pinned":"False","Title":"Campaigns Distribution(Promised)","Text":"Added at 5/15/2009 12:40:52 PM","Tag":"~/Development/Controls/DeveloperCampaignDistribution.ascx","Index":"0"} Telerik.Web.UI.DockState
-  [0] {"DockZoneID":"ctl00_contentpane_Top","Width":"","ExpandedHeight":"0","Height":"","Index":"0","Top":"","Left":"","Closed":"False","Resizable":"False","Collapsed":"False","Pinned":"False","UniqueName":"5eb163f6a40aaa4e42a8b15a3c768b30db0f","Tag":"~/Development/Controls/DeveloperCampaignDistribution.ascx","Title":"Campaigns Distribution(Promised)","Text":"Added at 5/15/2009 12:40:52 PM"} Telerik.Web.UI.DockState

How can I restore the width?
If you need code example, you can find it the previous support ticket.

Thank you.

1 Answer, 1 is accepted

Sort by
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 18 May 2009, 08:29 AM
"The problem comes from the fact that the Unit object cannot be serialized.  This means that once the object has been serialized and then deserialized, the properties such as Top, Left, Width and Height etc. will loose their values.
Please note that this has nothing to do with Telerik components but with the .NET Framework and missing serialization.This is a shortcoming of the .Net Framework but it could be overcomed. For example you could use the JavaScriptSerializer class to serialize the state of the docks and write your own implementation of a custom JavaScriptConverter class. This custom class will take care of serialization/deserialization of Unit objects."
You can find attached an example in this forum thread.
Another approach is to use ToString() - serialize, and  DockState.Deserialize(currentStateString); methods
e.g.
string stateString = String.Empty;  
        //Serialize all states in stateString  
        foreach (DockState state in RadDockLayout1.GetRegisteredDocksState())  
        {  
            stateString = stateString + state.ToString() + "|";  
        }  
        //Deserialize  
        string[] states = stateString.Split('|');  
        foreach (string currentStateString in states)  
        {  
            DockState currentState = DockState.Deserialize(currentStateString);  
        } 
 
Tags
Dock
Asked by
debett
Top achievements
Rank 1
Answers by
Obi-Wan Kenobi
Top achievements
Rank 1
Share this question
or