{"record":{"id":"b8c19f4706fe6f50","repo":"dotnet/wpf","slug":"sr-textelement-unmatchedendpointer","errorCode":null,"errorMessage":"SR.TextElement_UnmatchedEndPointer","messagePattern":"SR\\.TextElement_UnmatchedEndPointer","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElement.cs","lineNumber":100,"sourceCode":"        /// <remarks>\n        /// This method extracts the TextElement from its current position,\n        /// leaving behind any contained content, before inserting the TextElement\n        /// at a new location.\n        ///\n        /// If start is null, end must also be null, and the TextElement will\n        /// not be inserted into a new document.\n        /// </remarks>\n        internal void Reposition(TextPointer start, TextPointer end)\n        {\n            TextContainer tree;\n\n            if (start != null)\n            {\n                ValidationHelper.VerifyPositionPair(start, end);\n            }\n            else if (end != null)\n            {\n                throw new ArgumentException(SR.TextElement_UnmatchedEndPointer);\n            }\n\n            if (start != null)\n            {\n                // start/end must be equally scoped.  But we want to discount\n                // this TextElement when considering scoping -- it will be\n                // extracted before the final insert.\n\n                SplayTreeNode startNode = start.GetScopingNode();\n                SplayTreeNode endNode = end.GetScopingNode();\n\n                if (startNode == _textElementNode)\n                {\n                    startNode = _textElementNode.GetContainingNode();\n                }\n                if (endNode == _textElementNode)\n                {\n                    endNode = _textElementNode.GetContainingNode();","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElement.cs#L82-L118","documentation":"TextElement.Reposition validates that its start/end TextPointer arguments are paired. Passing an end pointer while start is null means the end cannot be verified against a matching start, so it throws ArgumentException with TextElement_UnmatchedEndPointer. The start/end pair must be supplied together or not at all.","triggerScenarios":"Calling Reposition (directly or via InsertElementClone, SplitElement, MergeParagraphs, PasteMergeableTextFragment, undo units) with start=null and a non-null end pointer.","commonSituations":"Programmatic construction of text elements in FlowDocument editing where only one boundary is computed; copy/paste code passing partial ranges.","solutions":["Pass both start and end pointers together, or pass neither.","If only one boundary is known, compute the matching boundary before calling.","Guard inputs: verify start/end are both null or both non-null before the call."],"exampleFix":"// before\nelement.Reposition(null, endPointer);\n// after\nif (startPointer != null && endPointer != null)\n    element.Reposition(startPointer, endPointer);\nelse\n    element.Reposition(null, null);","handlingStrategy":"validation","validationCode":"bool paired = (start == null && end == null) || (start != null && end != null);\nif (!paired) throw new ArgumentException(\"start and end must be supplied together\");","typeGuard":null,"tryCatchPattern":"try { element.Reposition(start, end); }\ncatch (ArgumentException) { /* repair the pointer pair and retry once */ }","preventionTips":["Always pass start/end as a pair","Validate pointer pairs at API boundaries","Prefer TextRange which enforces pairing"],"tags":["wpf","argument","textpointer"],"backgroundTag":"missing-required-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}