{"record":{"id":"fad2816a7c8833ff","repo":"microsoft/ailab","slug":"invalid-onenote-xml-unable-to-create-onenoteentity-xml-0","errorCode":null,"errorMessage":"Invalid OneNote xml. Unable to create OneNoteEntity. XML: {0}","messagePattern":"Invalid OneNote xml\\. Unable to create OneNoteEntity\\. XML: (.+?)","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"Snip-Insights/SnipInsight/SendTo/OneNoteManager.cs","lineNumber":429,"sourceCode":"         internal OneNoteEntity GetEntity(string hierarchyXml)\n        {\n            _xmlDoc.LoadXml(hierarchyXml);\n\n            XmlElement rootNode = _xmlDoc.DocumentElement;\n\n            OneNoteEntity entity = GetEntity(rootNode);\n\n            if (string.Compare(rootNode.Name, SectionNodeName, true) == 0)\n            {\n                return new OneNoteSection(entity.Id, entity.Name);\n            }\n            else if (string.Compare(rootNode.Name, PageNodeName, true) == 0)\n            {\n                return new OneNotePage(entity.Id, entity.Name);\n            }\n            else\n            {\n                throw new ApplicationException(string.Format(\"Invalid OneNote xml. Unable to create OneNoteEntity. XML: {0}\", hierarchyXml));\n            }\n        }\n\n        private OneNoteEntity GetEntity(XmlNode node)\n        {\n            string id = node.Attributes[\"ID\"].Value;\n            string name = node.Attributes[\"name\"].Value;\n\n            return new OneNoteEntity(id, name);\n        }\n\n        internal string GetInsertSnipXml(OneNotePage page, string base64ImageString, string publishUrl, bool addTitle)\n        {\n            const string xmlFormat =\n                \"<?xml version=\\\"1.0\\\"?>\" +\n                \"<one:Page xmlns:one=\\\"http://schemas.microsoft.com/office/onenote/2013/onenote\\\" ID=\\\"{0}\\\">\" +  // format {0} - page.ID\n                    \"{1}\" +                                                                                       // format {1} - titleXml\n                    \"<one:Outline>\" +","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/microsoft/ailab/blob/89fe2fc62081145ec5408d42059cbcb7c4a033c8/Snip-Insights/SnipInsight/SendTo/OneNoteManager.cs#L411-L447","documentation":"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.","triggerScenarios":"Thrown at Snip-Insights/SnipInsight/SendTo/OneNoteManager.cs:429 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Log the offending XML (the {0} payload) to diagnose whether the problem is malformed XML or an unexpected root node","Confirm the XML was requested with the xs2013 schema so the root is one:Section or one:Page","If other root types (e.g. Notebook) should be supported, extend GetEntity with matching OneNoteEntity subclasses instead of throwing"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"89fe2fc62081145ec5408d42059cbcb7c4a033c8","analyzedAt":"2026-09-13T20:10:53.835Z","contentChangedAt":"2026-09-13T20:10:53.835Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}