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

Deserialize generating an error

1 Answer 30 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 27 Jul 2009, 05:21 PM
Getting the following error:

System.InvalidCastException: Conversion from string "{"UniqueName":"dckOrderHistory"," to type 'Integer' is not valid. ---> System.FormatException: Input string was not in a correct format. at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) --- End of inner exception stack trace --- at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) at Dealers_Toolbox_portal.RetrievePortalState() in D:\Net Folders\Development Web Sites\Smoker\Dealers\Toolbox\portal.ascx.vb:line 51

Here is the value stored in the database:
{"UniqueName":"dckOrderHistory","DockZoneID":"ctl00_ContentPlaceHolder1_RadDock_RadDockZone1","Width":"300px","Height":"","ExpandedHeight":"0","Top":"0px","Left":"0px","Resizable":"False","Closed":"False","Collapsed":"False","Pinned":"False","Title":"Order History","Text":"","Tag":"~/Dealers/Toolbox/PortalControls/OrderHistory.ascx","Index":"1"}|{"UniqueName":"dckBrowseBoats","DockZoneID":"ctl00_ContentPlaceHolder1_RadDock_RadDockZone1","Width":"300px","Height":"","ExpandedHeight":"0","Top":"0px","Left":"0px","Resizable":"False","Closed":"False","Collapsed":"False","Pinned":"False","Title":"Browse Boats","Text":"","Tag":"~/Dealers/Toolbox/PortalControls/BrowseBoats.ascx","Index":"0"} 

Here is the code: (Line 51 is the Deserialize line)  What am I doing wrong?  Thanks!







Dim lDockState As New List(Of DockState) 
Dim sDockState() As String = oRdr.Item("PortalState").ToString.Split("|"c) 
 
For Each i As String In sDockState 
     Dim state As DockState = DockState.Deserialize(sDockState(i)) 
     lDockState.Add(state) 
Next 
 
RetrievePortalState = lDockState 

1 Answer, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 30 Jul 2009, 11:50 AM
Hi Matt,

I think the problem is that you are trying to deserialize sDockState(i), which is not the string to be deserialized. The "i" variable is not the index of the current serialized DockState in the sDockState list but, "i' itself is the serialized DockState and is the one that needs to be deserialized. So, your code should look like the following:

Dim lDockState As New List(Of DockState)  
Dim sDockState() As String = oRdr.Item("PortalState").ToString.Split("|"c)  
  
For Each i As String In sDockState  
     Dim state As DockState = DockState.Deserialize(i)  
     lDockState.Add(state)  
Next  
  
RetrievePortalState = lDockState  



All the best,
Pero
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.
Tags
Dock
Asked by
Matt
Top achievements
Rank 1
Answers by
Pero
Telerik team
Share this question
or