Invalid JSON primitive: In RadDockLayout1_LoadDockLayout

4 posts, 0 answers
  1. Rizwan
    Rizwan avatar
    2 posts
    Member since:
    Apr 2015

    Posted 06 Apr 2015 Link to this post

    Please help me to fix the following error: 

    Using: Microsoft Visual Studio Ultimate 2012, UI for ASP.NET AJAX Q1 2015

     

    Server Error in '/SmartTrace' Application.Invalid JSON primitive: **{"DockZoneID":"RadDockZone2","Width":{"Type":1,"Value":300,"IsEmpty":false},"ExpandedHeight":0,"Height":{"Type":1,"Value":0,"IsEmpty":true},"Index":0,"Top":{"Type":1,"Value":0,"IsEmpty":false},"Left":{"Type":1,"Value":0,"IsEmpty":false},"Closed":false,"Resizable":false,"Collapsed":false,"Pinned":false,"UniqueName":"RadDock2","Tag":null,"Title":"","Text":"","ControlSettings":[],"UniqueId":null,"UniqueKey":null}***{"DockZoneID":"RadDockZone3","Width":{"Type":1,"Value":300,"IsEmpty":false},"ExpandedHeight":0,"Height":{"Type":1,"Value":0,"IsEmpty":true},"Index":0,"Top":{"Type":1,"Value":0,"IsEmpty":false},"Left":{"Type":1,"Value":0,"IsEmpty":false},"Closed":false,"Resizable":false,"Collapsed":false,"Pinned":false,"UniqueName":"RadDock3","Tag":null,"Title":"","Text":"","ControlSettings":[],"UniqueId":null,"UniqueKey":null}***.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.ArgumentException: Invalid JSON primitive: **{"DockZoneID":"RadDockZone2","Width":{"Type":1,"Value":300,"IsEmpty":false},"ExpandedHeight":0,"Height":{"Type":1,"Value":0,"IsEmpty":true},"Index":0,"Top":{"Type":1,"Value":0,"IsEmpty":false},"Left":{"Type":1,"Value":0,"IsEmpty":false},"Closed":false,"Resizable":false,"Collapsed":false,"Pinned":false,"UniqueName":"RadDock2","Tag":null,"Title":"","Text":"","ControlSettings":[],"UniqueId":null,"UniqueKey":null}***{"DockZoneID":"RadDockZone3","Width":{"Type":1,"Value":300,"IsEmpty":false},"ExpandedHeight":0,"Height":{"Type":1,"Value":0,"IsEmpty":true},"Index":0,"Top":{"Type":1,"Value":0,"IsEmpty":false},"Left":{"Type":1,"Value":0,"IsEmpty":false},"Closed":false,"Resizable":false,"Collapsed":false,"Pinned":false,"UniqueName":"RadDock3","Tag":null,"Title":"","Text":"","ControlSettings":[],"UniqueId":null,"UniqueKey":null}***.

    Source Error: 

    Line 47: for (int i = 0; i < states.Length; i++)
    Line 48: {
    Line 49: DockState state = DockState.Deserialize(states[i]);
    Line 50: e.Positions[state.UniqueName] = state.DockZoneID;
    Line 51: e.Indices[state.UniqueName] = state.Index;
    Source File: d:\Projects\SmartTrace\Dashboard3.aspx.cs    Line: 49 

    Server Error in '/SmartTrace' Application.Invalid JSON primitive: **{"DockZoneID":"RadDockZone2","Width":{"Type":1,"Value":300,"IsEmpty":false},"ExpandedHeight":0,"Height":{"Type":1,"Value":0,"IsEmpty":true},"Index":0,"Top":{"Type":1,"Value":0,"IsEmpty":false},"Left":{"Type":1,"Value":0,"IsEmpty":false},"Closed":false,"Resizable":false,"Collapsed":false,"Pinned":false,"UniqueName":"RadDock2","Tag":null,"Title":"","Text":"","ControlSettings":[],"UniqueId":null,"UniqueKey":null}***{"DockZoneID":"RadDockZone3","Width":{"Type":1,"Value":300,"IsEmpty":false},"ExpandedHeight":0,"Height":{"Type":1,"Value":0,"IsEmpty":true},"Index":0,"Top":{"Type":1,"Value":0,"IsEmpty":false},"Left":{"Type":1,"Value":0,"IsEmpty":false},"Closed":false,"Resizable":false,"Collapsed":false,"Pinned":false,"UniqueName":"RadDock3","Tag":null,"Title":"","Text":"","ControlSettings":[],"UniqueId":null,"UniqueKey":null}***.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.ArgumentException: Invalid JSON primitive: **{"DockZoneID":"RadDockZone2","Width":{"Type":1,"Value":300,"IsEmpty":false},"ExpandedHeight":0,"Height":{"Type":1,"Value":0,"IsEmpty":true},"Index":0,"Top":{"Type":1,"Value":0,"IsEmpty":false},"Left":{"Type":1,"Value":0,"IsEmpty":false},"Closed":false,"Resizable":false,"Collapsed":false,"Pinned":false,"UniqueName":"RadDock2","Tag":null,"Title":"","Text":"","ControlSettings":[],"UniqueId":null,"UniqueKey":null}***{"DockZoneID":"RadDockZone3","Width":{"Type":1,"Value":300,"IsEmpty":false},"ExpandedHeight":0,"Height":{"Type":1,"Value":0,"IsEmpty":true},"Index":0,"Top":{"Type":1,"Value":0,"IsEmpty":false},"Left":{"Type":1,"Value":0,"IsEmpty":false},"Closed":false,"Resizable":false,"Collapsed":false,"Pinned":false,"UniqueName":"RadDock3","Tag":null,"Title":"","Text":"","ControlSettings":[],"UniqueId":null,"UniqueKey":null}***.

    Source Error: 

    Line 47: for (int i = 0; i < states.Length; i++)
    Line 48: {
    Line 49: DockState state = DockState.Deserialize(states[i]);
    Line 50: e.Positions[state.UniqueName] = state.DockZoneID;
    Line 51: e.Indices[state.UniqueName] = state.Index;
    Source File: d:\Projects\SmartTrace\Dashboard3.aspx.cs    Line: 49 
    :

    Server Error in '/Website1' Application.
     
    Invalid JSON primitive: **{"DockZoneID":"RadDockZone2","Width":{"Type":1,"Value":300,"IsEmpty":false},"ExpandedHeight":0,"Height":{"Type":1,"Value":0,"IsEmpty":true},"Index":0,"Top":{"Type":1,"Value":0,"IsEmpty":false},"Left":{"Type":1,"Value":0,"IsEmpty":false},"Closed":false,"Resizable":false,"Collapsed":false,"Pinned":false,"UniqueName":"RadDock2","Tag":null,"Title":"","Text":"","ControlSettings":[],"UniqueId":null,"UniqueKey":null}***{"DockZoneID":"RadDockZone3","Width":{"Type":1,"Value":300,"IsEmpty":false},"ExpandedHeight":0,"Height":{"Type":1,"Value":0,"IsEmpty":true},"Index":0,"Top":{"Type":1,"Value":0,"IsEmpty":false},"Left":{"Type":1,"Value":0,"IsEmpty":false},"Closed":false,"Resizable":false,"Collapsed":false,"Pinned":false,"UniqueName":"RadDock3","Tag":null,"Title":"","Text":"","ControlSettings":[],"UniqueId":null,"UniqueKey":null}***.
     
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
     
    Exception Details: System.ArgumentException: Invalid JSON primitive: **{"DockZoneID":"RadDockZone2","Width":{"Type":1,"Value":300,"IsEmpty":false},"ExpandedHeight":0,"Height":{"Type":1,"Value":0,"IsEmpty":true},"Index":0,"Top":{"Type":1,"Value":0,"IsEmpty":false},"Left":{"Type":1,"Value":0,"IsEmpty":false},"Closed":false,"Resizable":false,"Collapsed":false,"Pinned":false,"UniqueName":"RadDock2","Tag":null,"Title":"","Text":"","ControlSettings":[],"UniqueId":null,"UniqueKey":null}***{"DockZoneID":"RadDockZone3","Width":{"Type":1,"Value":300,"IsEmpty":false},"ExpandedHeight":0,"Height":{"Type":1,"Value":0,"IsEmpty":true},"Index":0,"Top":{"Type":1,"Value":0,"IsEmpty":false},"Left":{"Type":1,"Value":0,"IsEmpty":false},"Closed":false,"Resizable":false,"Collapsed":false,"Pinned":false,"UniqueName":"RadDock3","Tag":null,"Title":"","Text":"","ControlSettings":[],"UniqueId":null,"UniqueKey":null}***.
     
    Source Error:
     
     
    Line 47:                 for (int i = 0; i < states.Length; i++)
    Line 48:                 {
    Line 49:                     DockState state = DockState.Deserialize(states[i]);
    Line 50:                     e.Positions[state.UniqueName] = state.DockZoneID;
    Line 51:                     e.Indices[state.UniqueName] = state.Index;
     
    Source File: d:\Projects\SmartTrace\Dashboard3.aspx.cs    Line: 49

     

    ASPX Code:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Dashboard3.aspx.cs" Inherits="Dashboard3" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     
     
     
    <!DOCTYPE html>
     
    <head runat="server">
        <title></title>
         
    </head>
    <body>
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
                     
            <div>
                <telerik:RadDockLayout ID="RadDockLayout1" runat="server" OnSaveDockLayout="RadDockLayout1_SaveDockLayout" OnLoadDockLayout="RadDockLayout1_LoadDockLayout" EnableViewState="False" StoreLayoutInViewState="True">
                    <telerik:RadDockZone ID="RadDockZone1" runat="server" Height="300px" Width="300px">
                        <telerik:RadDock ID="RadDock1" runat="server" Width="300px" Title="Dock 1" >
                            <ContentTemplate>
                                content 1
                            </ContentTemplate>
                        </telerik:RadDock>
                        <telerik:RadDock ID="RadDock2" runat="server" Width="300px" Title="Dock 2" >
                            <ContentTemplate>
                                content 2
                            </ContentTemplate>
                        </telerik:RadDock>
                    </telerik:RadDockZone>
                </telerik:RadDockLayout>
     
            </div>
        </form>
     
     
    </body>
    </html>

     

    C# Code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
     
    public partial class Dashboard3 : System.Web.UI.Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            //RadDockLayout1.Controls.Add(RadDockZone1);
            //RadDockLayout1.Controls.Add(RadDockZone2);
            //RadDockLayout1.Controls.Add(RadDockZone3);
             
            //RadDockLayout1.Controls.Add(RadDock1);
            //RadDockLayout1.Controls.Add(RadDock2);
            //RadDockLayout1.Controls.Add(RadDock3);
     
           
     
     
     
        }
        protected void Page_Load(object sender, EventArgs e)
        {
     
        }
     
     
        protected void RadDockLayout1_SaveDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e)
        {
            HttpCookie dockState = Page.Response.Cookies.Get("DashboardDockStates");
            if (dockState == null)
            {
                dockState = new HttpCookie("DashboardDockStates");
                Page.Response.Cookies.Add(dockState);
            }
            List<DockState> stateList = ((RadDockLayout)sender).GetRegisteredDocksState();
            StringBuilder serializedList = new StringBuilder();
            for (int i = 0; i < stateList.Count; i++)
            {
                serializedList.Append(stateList[i].ToString());
                serializedList.Append("|");
            }
            dockState.Expires = DateTime.Today.AddMonths(1);
            dockState.Value = serializedList.ToString();
     
        }
        protected void RadDockLayout1_LoadDockLayout(object sender, DockLayoutEventArgs e)
        {
            HttpCookie dockState = Page.Request.Cookies.Get("DashboardDockStates");
            if (dockState != null)
            {
                string serializedList = dockState.Value;
                if (serializedList != null)
                {
                    string[] states = serializedList.Split('|');
                    for (int i = 0; i < states.Length; i++)
                    {
                        DockState state = DockState.Deserialize(states[i]);
                        e.Positions[state.UniqueName] = state.DockZoneID;
                        e.Indices[state.UniqueName] = state.Index;
                    }
                }
            }
        }
     
         
    }
     

     

     

     

  2. Rizwan
    Rizwan avatar
    2 posts
    Member since:
    Apr 2015

    Posted 06 Apr 2015 in reply to Rizwan Link to this post

    Google Chrome Version 41.0.2272.118, throws above error

    IE 11: runs the page but dosn't show the updated state after page refresh or close & open

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 07 Apr 2015 Link to this post

    Hi Rizwan,

    I am posting the response from the support ticket here, so that it can be reviewed by users that encounter the same issue:

    There appears to be something wrong with the dock state according to the information in the exception you received.

    Note that the delimiter that is used in the dock state, shown in the exception information, is "***", however in the code you posted "|" is used. As a result, the content of the cookie you specified will not be split in valid JSON primitives, which will lead to problems with the deserialization of these primitives.

    Another thing I noticed is that the JSON primitives that are visible in the exception information are not in the exact format that is currently used by the RadDock control for its state. I am attaching a package that contains a text file with the cookie content I retrieved by running a test page that is also included. Please compare it with the exception output to check the differences.

    If the issue is indeed caused by an incorrect format of the dock state, it should be resolved by clearing the cookie so that a new one that has the correct dock state is created. If that does not help, you could modify the page I sent so that it isolates the issue and send it back for further inspection.

    I would also like to point out that cookies have a limited size, thus it is not recommended to use them in scenarios with a lot of docks. When the limit is reached, the content of the cookie will be cut, which will again lead to an incorrect dock state.


    In case you are still having difficulties after trying the suggestion above, let us continue our discussion in the support ticket. When there is a concrete solution, you can update this thread.

    Regards,
    Slav
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  5. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 07 Apr 2015 Link to this post

    Hi Rizwan,

    I forgot to attach the files I mentioned. You can download them from this post.

    Regards,
    Slav
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top