{"record":{"id":"d5d44519715786bf","repo":"dotnet/wpf","slug":"sr-format-sr-indifferentscope-start-end","errorCode":null,"errorMessage":"SR.Format(SR.InDifferentScope, \"start\", \"end\")","messagePattern":"SR\\.Format\\(SR\\.InDifferentScope, \"start\", \"end\"\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElement.cs","lineNumber":123,"sourceCode":"                // 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();\n                }\n\n                if (startNode != endNode)\n                {\n                    throw new ArgumentException(SR.Format(SR.InDifferentScope, \"start\", \"end\"));\n                }\n            }\n\n            if (this.IsInTree)\n            {\n                tree = EnsureTextContainer();\n\n                if (start == null)\n                {\n                    //\n                    // Case 0: Extract this element from its tree.\n                    //\n\n                    tree.BeginChange();\n                    try\n                    {\n                        tree.ExtractElementInternal(this);\n                    }","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElement.cs#L105-L141","documentation":"TextElement.Reposition requires start and end pointers to be equally scoped, i.e. contained by the same tree node. When their containing nodes differ it throws ArgumentException with the InDifferentScope message naming 'start' and 'end'. This prevents repositioning an element with a range that crosses element boundaries.","triggerScenarios":"Calling Reposition with a start/end pair whose GetContainingNode() values differ (e.g. start in one Paragraph, end in another).","commonSituations":"Selection ranges spanning multiple paragraphs passed to element repositioning; paste/merge operations in FlowDocument where range endpoints land in different scopes.","solutions":["Ensure start and end are within the same containing element before calling Reposition.","Split or clamp the range so both endpoints share a scope.","Use a TextRange/selection API that handles cross-element ranges instead of Reposition directly."],"exampleFix":"// before\nelement.Reposition(startPointerInP1, endPointerInP2);\n// after\nif (startPointerInP1.Parent == endPointerInP2.Parent)\n    element.Reposition(startPointerInP1, endPointerInP2);","handlingStrategy":"validation","validationCode":"bool sameScope = start == null || start.GetContainingNode() == end.GetContainingNode();\nif (!sameScope) throw new ArgumentException(\"start/end must share scope\");","typeGuard":null,"tryCatchPattern":"try { element.Reposition(start, end); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"different scope\")) { /* split the range and reposition per scope */ }","preventionTips":["Verify both endpoints are in the same containing element","Clamp selections to a single element before repositioning","Use TextRange APIs for cross-element ranges"],"tags":["wpf","argument","scope"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}