{"record":{"id":"f01c32599546f606","repo":"dotnet/wpf","slug":"argument-out-of-range-position-not-contained-in-view","errorCode":null,"errorMessage":"Argument out of range (position not contained in view)","messagePattern":"Argument out of range \\(position not contained in view\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs","lineNumber":92,"sourceCode":"        }\n\n        /// <summary>\n        /// <see cref=\"ITextView.GetRawRectangleFromTextPosition\"/>\n        /// </summary>\n        /// <remarks>\n        /// TextDocumentView does not calculate any transform for this function. Transform returned is always identity.\n        /// </remarks>\n        internal override Rect GetRawRectangleFromTextPosition(ITextPointer position, out Transform transform)\n        {\n            // Verify that layout information is valid. Cannot continue if not valid.\n            if (!IsValid)\n            {\n                throw new InvalidOperationException(SR.TextViewInvalidLayout);\n            }\n            ValidationHelper.VerifyPosition(_textContainer, position, nameof(position));\n            if (!ContainsCore(position))\n            {\n                throw new ArgumentOutOfRangeException(nameof(position));\n            }\n            _owner.EnsureValidVisuals();\n\n            Rect rect = GetRectangleFromTextPosition(Columns, FloatingElements, position);\n\n            // Transforms Rect from content's coordinate system.\n            TransformFromContent(ref rect, out transform);\n\n            return rect;\n        }\n\n        /// <summary>\n        /// <see cref=\"TextViewBase.GetTightBoundingGeometryFromTextPositions\"/>\n        /// </summary>\n        internal override Geometry GetTightBoundingGeometryFromTextPositions(ITextPointer startPosition, ITextPointer endPosition)\n        {\n            Geometry geometry = null;\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs#L74-L110","documentation":"Within GetRawRectangleFromTextPosition, after layout validity and container checks, ContainsCore(position) verifies the position lies within this view's layout span. If not, ArgumentOutOfRangeException(nameof(position)) is thrown with the message 'Argument out of range (position not contained in view)'.","triggerScenarios":"Passing an ITextPointer that belongs to the same TextContainer but sits outside the range covered by this view's Columns/FloatingElements — e.g. content on another page or beyond a virtualized viewport.","commonSituations":"Paged documents (FixedDocument/FlowDocument views per page) where a position belongs to a different page view; positions in collapsed or filtered-out content.","solutions":["Check Contains(position) (or ContainsCore) before calling and route the position to the correct view.","Use the TextDocumentView associated with the position's containing page/subview.","Handle the exception and fall back to the TextViewService that can locate the right view.","Clamp the position to the view's start/end before querying the rectangle."],"exampleFix":"// before\nvar rect = view.GetRawRectangleFromTextPosition(pos, out var t);\n// after\nif (view.Contains(pos))\n    var rect = view.GetRawRectangleFromTextPosition(pos, out var t);","handlingStrategy":"type-guard","validationCode":"if (!view.Contains(position)) { /* route to the correct view */ }","typeGuard":"static bool PositionInView(ITextView view, ITextPointer p) => view.Contains(p);","tryCatchPattern":"try { rect = view.GetRawRectangleFromTextPosition(position, out transform); }\ncatch (ArgumentOutOfRangeException) { rect = null; // not in this view }","preventionTips":["Match positions to their containing page/subview before rect computation.","Clamp positions to the view's start/end span when approximating is acceptable.","In paged documents, resolve the view via the TextMap/TextViewService.","Never assume one view covers the whole document."],"tags":["wpf","argumentoutofrangeexception","textview","pagination"],"backgroundTag":"position-not-in-view","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"}