microsoft/ailab · error · ApplicationException

Invalid OneNote xml. Unable to create OneNoteEntity. XML

Error message

Invalid OneNote xml. Unable to create OneNoteEntity. XML: {0}

What it means

GetEntity loads the OneNote hierarchy XML into an XmlDocument and inspects the root element name; the recognized roots are a Section node or a Page node, and any other root means the XML is not a parseable OneNote hierarchy this class understands. This validation guard fires when hierarchyXml is malformed XML (LoadXml fails), or its document element is neither Section nor Page — for example the wrong schema or a full notebook hierarchy instead of a section/page.

Solutions

  1. Log the offending XML (the {0} payload) to diagnose whether the problem is malformed XML or an unexpected root node
  2. Confirm the XML was requested with the xs2013 schema so the root is one:Section or one:Page
  3. If other root types (e.g. Notebook) should be supported, extend GetEntity with matching OneNoteEntity subclasses instead of throwing
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at Snip-Insights/SnipInsight/SendTo/OneNoteManager.cs:429 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of microsoft/ailab@89fe2fc620 (2026-09-13). Data as JSON: /api/errors/fad2816a7c8833ff. Report an issue: GitHub.

Appendix: source

Thrown at Snip-Insights/SnipInsight/SendTo/OneNoteManager.cs:429

         internal OneNoteEntity GetEntity(string hierarchyXml)
        {
            _xmlDoc.LoadXml(hierarchyXml);

            XmlElement rootNode = _xmlDoc.DocumentElement;

            OneNoteEntity entity = GetEntity(rootNode);

            if (string.Compare(rootNode.Name, SectionNodeName, true) == 0)
            {
                return new OneNoteSection(entity.Id, entity.Name);
            }
            else if (string.Compare(rootNode.Name, PageNodeName, true) == 0)
            {
                return new OneNotePage(entity.Id, entity.Name);
            }
            else
            {
                throw new ApplicationException(string.Format("Invalid OneNote xml. Unable to create OneNoteEntity. XML: {0}", hierarchyXml));
            }
        }

        private OneNoteEntity GetEntity(XmlNode node)
        {
            string id = node.Attributes["ID"].Value;
            string name = node.Attributes["name"].Value;

            return new OneNoteEntity(id, name);
        }

        internal string GetInsertSnipXml(OneNotePage page, string base64ImageString, string publishUrl, bool addTitle)
        {
            const string xmlFormat =
                "<?xml version=\"1.0\"?>" +
                "<one:Page xmlns:one=\"http://schemas.microsoft.com/office/onenote/2013/onenote\" ID=\"{0}\">" +  // format {0} - page.ID
                    "{1}" +                                                                                       // format {1} - titleXml
                    "<one:Outline>" +

View on GitHub (pinned to 89fe2fc620)