Deserialize generating an error

2 posts, 0 answers
  1. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2009

    Posted 27 Jul 2009 Link to this post

    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)) 
    RetrievePortalState = lDockState 
  2. Pero
    Pero avatar
    1156 posts

    Posted 30 Jul 2009 Link to this post

    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)  
    RetrievePortalState = lDockState  

    All the best,
    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.
Back to Top