{"record":{"id":"a13b6f423eee3b29","repo":"iOfficeAI/OfficeCLI","slug":"drawing-group-anchor-xml-is-not-a-valid-xdr-twocel","errorCode":null,"errorMessage":"drawing-group anchor XML is not a valid xdr:twoCellAnchor: {ex.Message}","messagePattern":"drawing-group anchor XML is not a valid xdr:twoCellAnchor: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.cs","lineNumber":1135,"sourceCode":"                // to semantic leaf shapes when a group references package\n                // parts such as images/charts.\n                var groupSheetName = parentPartPath.TrimStart('/');\n                var groupWorksheet = FindWorksheet(groupSheetName)\n                    ?? throw new ArgumentException(\n                        $\"Sheet not found: {groupSheetName}. drawing-group must be added under a sheet.\");\n                properties ??= new Dictionary<string, string>();\n                var anchorXml = properties.GetValueOrDefault(\"anchor-xml\")\n                    ?? throw new ArgumentException(\n                        \"'anchor-xml' property is required for drawing-group (verbatim xdr anchor XML)\");\n\n                XDR.TwoCellAnchor groupAnchor;\n                try\n                {\n                    groupAnchor = new XDR.TwoCellAnchor(anchorXml);\n                }\n                catch (Exception ex)\n                {\n                    throw new ArgumentException(\n                        $\"drawing-group anchor XML is not a valid xdr:twoCellAnchor: {ex.Message}\", ex);\n                }\n                if (groupAnchor.GetFirstChild<XDR.GroupShape>() == null)\n                    throw new ArgumentException(\n                        \"drawing-group anchor XML must contain a top-level xdr:grpSp.\");\n\n                List<DumpDrawingHyperlinkSpec> groupHyperlinks;\n                try\n                {\n                    groupHyperlinks = DecodeDumpDrawingHyperlinks(\n                        properties.GetValueOrDefault(\"hyperlinks\") ?? \"\");\n                }\n                catch (FormatException ex)\n                {\n                    throw new ArgumentException(\n                        $\"drawing-group 'hyperlinks' carrier is invalid: {ex.Message}\", ex);\n                }\n","sourceCodeStart":1117,"sourceCodeEnd":1153,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.cs#L1117-L1153","documentation":"The 'anchor-xml' string was passed to the OpenXML SDK constructor `new XDR.TwoCellAnchor(anchorXml)` and it threw. This means the value is present but is not parseable as an xdr:twoCellAnchor element — malformed XML, wrong root element, undeclared namespace prefix, or a non-XML payload (e.g. still base64-encoded). The original exception message is embedded for diagnosis.","triggerScenarios":"anchor-xml is truncated, has HTML-escaped entities (&lt; instead of <), is missing the xdr namespace declaration, has a different root element (e.g. <xdr:wsDr> or <xdr:absoluteAnchor>), or was left base64-encoded from the dump.","commonSituations":"Copy-paste truncation of a large group anchor; a transport layer that HTML-escaped the XML; forgetting that the dump emits base64 XML elsewhere and assuming anchor-xml is also encoded; mismatched OpenXML SDK version that rejects the namespace.","solutions":["Ensure anchor-xml is raw, well-formed XML with the xdr namespace declared.","If you sourced it from a base64 field, decode it first (Convert.FromBase64String then UTF-8 decode).","Load it through XDocument.Parse in a scratch test to isolate the parse error from the SDK.","Confirm the root is <xdr:twoCellAnchor>, not a wrapper."],"exampleFix":"// before — still base64 encoded\nprops[\"anchor-xml\"] = \"PHhkcjp0d29DZWxsQW5jaG9y...\";\n// after — decoded raw XML\nprops[\"anchor-xml\"] = System.Text.Encoding.UTF8.GetString(\n    Convert.FromBase64String(\"PHhkcjp0d29DZWxsQW5jaG9y...\"));","handlingStrategy":"try-catch","validationCode":"try { _ = System.Xml.Linq.XDocument.Parse(props[\"anchor-xml\"]); }\ncatch (System.Xml.XmlException ex) { /* surface parse error before AddPart */ }","typeGuard":"static bool AnchorParses(string xml)\n{ try { return System.Xml.Linq.XDocument.Parse(xml) != null; } catch { return false; } }","tryCatchPattern":"try { handler.AddPart(parent, \"drawing-group\", props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"not a valid xdr:twoCellAnchor\"))\n{ /* inspect ex.InnerException, fix markup, decode if still base64 */ }","preventionTips":["Pre-parse anchor-xml with XDocument.Parse to catch XML errors early.","Decode base64 payloads before assigning to anchor-xml.","Confirm the root element is xdr:twoCellAnchor with the xdr namespace declared."],"tags":["excel","openxml","add-part","drawing-group","xml-parse"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}