Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nik Wahlberg 639 posts 1237 karma points MVP
    Sep 03, 2010 @ 19:40
    Nik Wahlberg
    0

    Custom tree worked in 4.0.x but not in 4.5

    Hi all,

    I am trying to port an older site to 4.5 and ran into this rather suspicious error with one of my custom trees. I am trying to use a custom members tree instead of showing the a,b,c,d....folder structure and use my own editing features as member properties live in a custom DB. 

    So, I simply pointed umbracoAppTree member to my new assemply and handler (like in the 'old' app). When I load the tree my Members node shows up but when I try to expand the node, I get the follwing exception:

    <html>
        <head>
            <title>Data at the root level is invalid. Line 1, position 1.</title>
            <style>
             body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
             p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
             b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
             H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
             H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
             pre {font-family:"Lucida Console";font-size: .9em}
             .marker {font-weight: bold; color: black;text-decoration: none;}
             .version {color: gray;}
             .error {margin-bottom: 10px;}
             .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
            </style>
        </head>
    
        <body bgcolor="white">
    
                <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
    
                <h2> <i>Data at the root level is invalid. Line 1, position 1.</i> </h2></span>
    
                <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
    
                <b> Description: </b>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.
    
                <br><br>
    
                <b> Exception Details: </b>System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.<br><br>
    
                <b>Source Error:</b> <br><br>
    
                <table width=100% bgcolor="#ffffcc">
                   <tr>
                      <td>
                          <code><pre>
    
    Line 87:         {
    Line 88:             XmlDocument xDoc = new XmlDocument();
    <font color=red>Line 89:             xDoc.LoadXml(tree.ToString());
    </font>Line 90:             Render(ref xDoc);
    Line 91:             tree = SerializableData.Deserialize(xDoc.OuterXml, typeof (XmlTree)) as XmlTree;</pre></code>
    
                      </td>
                   </tr>
                </table>
    
                <br>
    
                <b> Source File: </b> E:\Code\My Dropbox\Code\Scandia SVN\Scandia.Sites.LongbowCap.com\Trees\loadMembers.cs<b> &nbsp;&nbsp; Line: </b> 89
                <br><br>
    
                <b>Stack Trace:</b> <br><br>
    
                <table width=100% bgcolor="#ffffcc">
                   <tr>
                      <td>
                          <code><pre>
    
    [XmlException: Data at the root level is invalid. Line 1, position 1.]
       System.Xml.XmlTextReaderImpl.Throw(Exception e) +73
       System.Xml.XmlTextReaderImpl.Throw(String res, String arg) +122
       System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() +4076201
       System.Xml.XmlTextReaderImpl.ParseDocumentContent() +189
       System.Xml.XmlTextReaderImpl.Read() +145
       System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) +114
       System.Xml.XmlDocument.Load(XmlReader reader) +114
       System.Xml.XmlDocument.LoadXml(String xml) +168
       Scandia.Sites.LongbowCap.com.LoadMembers.Render(XmlTree&amp; tree) in E:\Code\My Dropbox\Code\Scandia SVN\Scandia.Sites.LongbowCap.com\Trees\loadMembers.cs:89
       umbraco.presentation.webservices.TreeDataService.LoadTree(TreeRequestParams treeParams) +157
       umbraco.presentation.webservices.TreeDataService.GetXmlTree() +198
       umbraco.presentation.webservices.TreeDataService.ProcessRequest(HttpContext context) +85
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +75
    </pre></code>
    
                      </td>
                   </tr>
                </table>
    
                <br>
    
                <hr width=100% size=1 color=silver>
    
                <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
    
                </font>
    
        </body>
    </html>
    <!-- 
    [XmlException]: Data at the root level is invalid. Line 1, position 1.
       at System.Xml.XmlTextReaderImpl.Throw(Exception e)
       at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
       at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
       at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
       at System.Xml.XmlTextReaderImpl.Read()
       at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
       at System.Xml.XmlDocument.Load(XmlReader reader)
       at System.Xml.XmlDocument.LoadXml(String xml)
       at Scandia.Sites.LongbowCap.com.LoadMembers.Render(XmlTree& tree) in E:\Code\My Dropbox\Code\Scandia SVN\Scandia.Sites.LongbowCap.com\Trees\loadMembers.cs:line 89
       at umbraco.presentation.webservices.TreeDataService.LoadTree(TreeRequestParams treeParams)
       at umbraco.presentation.webservices.TreeDataService.GetXmlTree()
       at umbraco.presentation.webservices.TreeDataService.ProcessRequest(HttpContext context)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    

    I'm sure it's some commonly known issue between compatibility, but I've been out of the look for a bit. Here's what the tree looks like:

    /// <summary>
        /// Handles loading of the member application into the application tree
        /// </summary>
        public class LoadMembers : BaseTree
        {
            public LoadMembers(string application) : base(application)
            {
            }
    
            protected override void CreateRootNode(ref XmlTreeNode rootNode)
            {
                rootNode.Icon = FolderIcon;
                rootNode.OpenIcon = FolderIconOpen;
                rootNode.NodeType = "init" + TreeAlias;
                rootNode.NodeID = "init";
            }
    
            /// <summary>
            /// Renders the Javascript.
            /// </summary>
            /// <param name="Javascript">The javascript.</param>
            public override void RenderJS(ref StringBuilder Javascript)
            {
                Javascript.Append(
                    @"
    function openMember(id) {
        parent.right.document.location.href = 'members/editMember.aspx?id=' + id;
    }
    
    function searchMembers(id) {
        parent.right.document.location.href = 'members/SearchMembers.aspx';
    }
    
    function viewMembers(letter) {
        parent.right.document.location.href = 'members/viewMembers.aspx?letter=' + letter;
    }
    
    function openContentItem(id) {
        parent.right.document.location.href = 'ContentItem/edit.aspx?id=' + id;
    }
    
    function openMemberExport() {
        parent.right.document.location.href = 'members/MemberExport.aspx';
    }
    
    function openRecruiterList() {
        parent.right.document.location.href = 'members/Recruiters.aspx';
    }
    
    function openCompanyList() {
        parent.right.document.location.href = 'members/Companies.aspx';
    }
    
    function openSendNewsletter() {
        parent.right.document.location.href = 'members/SendNewsletter.aspx';
    }
    
    function openDownloadResumes() {
        parent.right.document.location.href = 'members/DownloadResumes.aspx';
    }
    ");
            }
    
            /// <summary>
            /// This will call the normal Render method by passing the converted XmlTree to an XmlDocument.
            /// TODO: need to update this render method to do everything that the obsolete render method does and remove the obsolete method
            /// </summary>
            /// <param name="tree"></param>
            public override void Render(ref XmlTree tree)
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(tree.ToString());
                Render(ref xDoc);
                tree = SerializableData.Deserialize(xDoc.OuterXml, typeof (XmlTree)) as XmlTree;
            }
    
            /// <summary>
            /// Renders the specified tree item.
            /// </summary> 
            /// <param name="Tree">The tree.</param>
            public override void Render(ref XmlDocument Tree)
            {
                string letter = "";
                string ContentItemParent = "";
                if (HttpContext.Current.Request.QueryString.ToString().IndexOf("letter") >= 0)
                {
                    letter = HttpContext.Current.Request.QueryString.Get("letter");
                }
                if (HttpContext.Current.Request.QueryString.ToString().IndexOf("ContentItemParent") >= 0)
                {
                    ContentItemParent = HttpContext.Current.Request.QueryString.Get("ContentItemParent");
                }
                // letter = ;
    
                XmlNode root = Tree.DocumentElement;
                if (letter != "")
                {
                }
                else
                {
                    // Search Member
                    XmlElement treeElementSearch = Tree.CreateElement("tree");
                    treeElementSearch.SetAttribute("menu", "");
                    treeElementSearch.SetAttribute("nodeID", "Search");
                    treeElementSearch.SetAttribute("text", ui.Text("search"));
                    treeElementSearch.SetAttribute("action", "javascript:searchMembers();");
                    treeElementSearch.SetAttribute("src", "");
                    treeElementSearch.SetAttribute("icon", FolderIcon);
                    treeElementSearch.SetAttribute("openIcon", FolderIcon);
                    treeElementSearch.SetAttribute("nodeType", "member");
    
                    root.AppendChild(treeElementSearch);
    
                    // Recruiter List
                    XmlElement treeElementRecruiterList = Tree.CreateElement("tree");
                    treeElementRecruiterList.SetAttribute("menu", "");
                    treeElementRecruiterList.SetAttribute("nodeID", "RecruiterList");
                    treeElementRecruiterList.SetAttribute("text", ui.Text("RecruiterList"));
                    treeElementRecruiterList.SetAttribute("action", "javascript:openRecruiterList();");
                    treeElementRecruiterList.SetAttribute("src", "");
                    treeElementRecruiterList.SetAttribute("icon", FolderIcon);
                    treeElementRecruiterList.SetAttribute("openIcon", FolderIcon);
                    treeElementRecruiterList.SetAttribute("nodeType", "member");
    
                    root.AppendChild(treeElementRecruiterList);
    
                    // Company List
                    XmlElement treeElementCompanyList = Tree.CreateElement("tree");
                    treeElementCompanyList.SetAttribute("menu", "");
                    treeElementCompanyList.SetAttribute("nodeID", "CompanyList");
                    treeElementCompanyList.SetAttribute("text", ui.Text("CompanyList"));
                    treeElementCompanyList.SetAttribute("action", "javascript:openCompanyList();");
                    treeElementCompanyList.SetAttribute("src", "");
                    treeElementCompanyList.SetAttribute("icon", FolderIcon);
                    treeElementCompanyList.SetAttribute("openIcon", FolderIcon);
                    treeElementCompanyList.SetAttribute("nodeType", "member");
    
                    root.AppendChild(treeElementCompanyList);
    
                    // Send newsletter via Emails 
                    XmlElement treeElementSendEmails = Tree.CreateElement("tree");
                    treeElementSendEmails.SetAttribute("menu", "");
                    treeElementSendEmails.SetAttribute("nodeID", "Send Newsletter Via Email");
                    treeElementSendEmails.SetAttribute("text", ui.Text("sendemails"));
                    treeElementSendEmails.SetAttribute("action", "javascript:openSendNewsletter();");
                    treeElementSendEmails.SetAttribute("src", "");
                    treeElementSendEmails.SetAttribute("icon", FolderIcon);
                    treeElementSendEmails.SetAttribute("openIcon", FolderIcon);
                    treeElementSendEmails.SetAttribute("nodeType", "member");
    
                    root.AppendChild(treeElementSendEmails);
    
    
                    // Export Emails 
                    XmlElement treeElementExportEmails = Tree.CreateElement("tree");
                    treeElementExportEmails.SetAttribute("menu", "");
                    treeElementExportEmails.SetAttribute("nodeID", "Export Email Addresses");
                    treeElementExportEmails.SetAttribute("text", ui.Text("exportemails"));
                    treeElementExportEmails.SetAttribute("action", "javascript:openMemberExport();");
                    treeElementExportEmails.SetAttribute("src", "");
                    treeElementExportEmails.SetAttribute("icon", FolderIcon);
                    treeElementExportEmails.SetAttribute("openIcon", FolderIcon);
                    treeElementExportEmails.SetAttribute("nodeType", "member");
    
                    root.AppendChild(treeElementExportEmails);
    
    
                    // Download Resumes 
                    XmlElement treeElementDownloadResumes = Tree.CreateElement("tree");
                    treeElementDownloadResumes.SetAttribute("menu", "");
                    treeElementDownloadResumes.SetAttribute("nodeID", "Download Resumes");
                    treeElementDownloadResumes.SetAttribute("text", ui.Text("downloadresumes"));
                    treeElementDownloadResumes.SetAttribute("action", "javascript:openDownloadResumes();");
                    treeElementDownloadResumes.SetAttribute("src", "");
                    treeElementDownloadResumes.SetAttribute("icon", FolderIcon);
                    treeElementDownloadResumes.SetAttribute("openIcon", FolderIcon);
                    treeElementDownloadResumes.SetAttribute("nodeType", "member");
    
                    root.AppendChild(treeElementDownloadResumes);
    
                }
            }
        }

    Thanks,
    Nik

  • Dean 55 posts 98 karma points
    Nov 19, 2010 @ 00:28
    Dean
    0

    Hello,

    I've stumblled across what I think is the same issue. Did you manage to find a solution? My tree is not throwing an exception, but if I try to expand my custom tree, it is empty.

    If I try and debug my by class that overrides basetree, breakpoints don't get hit.

    I have not changed anything from my 4.0 v.

     

    Cheers

    Deano

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Nov 19, 2010 @ 01:22
    Nik Wahlberg
    0

    Hi Deano, the above is simply depracated code and was introduced (I think) in v3. I inherited a site that was built with the code and never even thought about it. The new syntax should be more along the lines of this:

    public override void Render(ref XmlTree tree)
            {
                XmlTreeNode xNode = XmlTreeNode.Create(this);
    
                xNode.NodeID = "serachjobs";
                xNode.Text = "Search";
                xNode.Action = "javascript:openCustomAction();";
                xNode.Icon = "folder.gif";
                xNode.OpenIcon = "folder_o.gif";
    
                tree.Add(xNode);
            }
    /// <summary>
            /// Renders the Javascript.
            /// </summary>
            /// <param name="Javascript">The javascript.</param>
            public override void RenderJS(ref StringBuilder Javascript)
            {
                Javascript.Append(
                    @"
    function openCustomAction() {
    parent.right.document.location.href = 'plugins/custom.aspx'; } "); }

    Hope this helps.

    -- Nik

  • Dean 55 posts 98 karma points
    Nov 19, 2010 @ 01:27
    Dean
    0

    Hey Nik,

    Thanks for that. Turns out my class that builds the tree was under a sub namespace. I'm not saying that correctly probably, but what I mean is that it wasn't assembly.class, it was assyembly.folder.folder.class.

    That broke it. I just took the class out of that namespace and it worked again.

    Cheers

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Nov 19, 2010 @ 09:46
    Richard Soeteman
    0

    The tree rendering is different between 4.0 and 4.5. 4.0 expects that you use inline javascript and 4.5 wants you to use javascript functions. I wrote a blogpost on this subject a while back how to support both 4.0 and 4.5 in your package.

    Cheers,

    Richard

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Nov 19, 2010 @ 13:08
    Nik Wahlberg
    0

    Thanks for chiming in RIchard. In this case (my orignal issue wich has long been solved), I was using the wrong tree implementation all together. I did catch your post on the JS compat issues which is a nice resource.

    Cheers!

    -- Nik

Please Sign in or register to post replies

Write your reply to:

Draft