Loading XML Format Issue

3 posts, 0 answers
  1. Avidan
    Avidan avatar
    19 posts
    Member since:
    Sep 2012

    Posted 08 Dec 2010 Link to this post

    Hi,

    I have a server ajax control which inherits RadToolBar control, with OnInit event I popolate items from XML file (the file was taken from the Demo website, so I assume it's format is correct) 
    Imports System
    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Text
    Imports System.Web
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports Telerik.Web.UI
      
      
      
    Public Class GridCommandItem
        Inherits RadToolBar
        Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
            MyBase.OnInit(e)
            Me.LoadContentFile("ToolBar.xml")
        End Sub
         
    End Class

    When I place the server control on page and run the application I got the following error:

    Server Error in '/' Application.
    --------------------------------------------------------------------------------
      
    <ToolBar xmlns=''> was not expected. 
    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.InvalidOperationException: <ToolBar xmlns=''> was not expected.
      
    Source Error
      
      
    Line 14:     Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
    Line 15:         MyBase.OnInit(e)
    Line 16:         Me.LoadContentFile("ToolBar.xml")
    Line 17:     End Sub
    Line 18:    
       
      
    Source File: D:\Profiles\bah029\My Documents\Visual Studio 2008\Projects\CommonServerControls\GridCommandItem.vb    Line: 16 
      
    Stack Trace: 
      
      
    [InvalidOperationException: <ToolBar xmlns=''> was not expected.]
       Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderGridCommandItem.Read1_GridCommandItem() +259
      
    [InvalidOperationException: There is an error in XML document (2, 2).]
       System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) +613
       System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader) +102
       Telerik.Web.UI.ControlItemContainer.LoadXml(String xml) +113
       Telerik.Web.UI.RadToolBar.LoadContentFile(String xmlFileName) +99
       CommonServerControls.GridCommandItem.OnInit(EventArgs e) in D:\Profiles\bah029\My Documents\Visual Studio 2008\Projects\CommonServerControls\GridCommandItem.vb:16
       System.Web.UI.Control.InitRecursive(Control namingContainer) +333
       System.Web.UI.Control.InitRecursive(Control namingContainer) +210
       System.Web.UI.Control.InitRecursive(Control namingContainer) +210
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +378
      
      

    any idea how to solve it?

    Avidan
  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 09 Dec 2010 Link to this post

    Hello Avi,

    What does this ToolBar.xml file look like? Does it have <ToolBar xmlns=''>, like the error message states? If so, the root ToolBar element should not have any attributes set.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 12 Dec 2010 Link to this post

    Hello guys,

    The exception is thrown because the XmlSerializer by default expects the root element of the XML document being loaded to match the type name of the class to which it deserializes the document. In your case, this is the name of your custom class - GridCommandItem.

    So you can either rename the root element of the content XML document to GridCommandItem or set the XmlRootAttribute to your class to designate the expected name of the root node of the content XML document, e.g.
    <XmlRoot("ToolBar")> _
    Public Class GridCommandItem
        Inherits RadToolBar
     
    End Class

    I hope this helps.

    Regards,
    Simon
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top