{"record":{"id":"8c727bd33900d94d","repo":"dotnet/wpf","slug":"sr-textprovider-invalidpoint","errorCode":null,"errorMessage":"SR.TextProvider_InvalidPoint","messagePattern":"SR\\.TextProvider_InvalidPoint","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextAdaptor.cs","lineNumber":667,"sourceCode":"        /// if they are not.</param>\n        /// <returns>A degenerate range nearest the specified location.</returns>\n        ITextRangeProvider ITextProvider.RangeFromPoint(Point location)\n        {\n            TextRangeAdaptor range = null;\n            ITextView textView = GetUpdatedTextView();\n            if (textView != null)\n            {\n                // Convert the screen point to the element space coordinates.\n                location = ScreenToClient(location, textView.RenderScope);\n                ITextPointer position = textView.GetTextPositionFromPoint(location, true);\n                if (position != null)\n                {\n                    range = new TextRangeAdaptor(this, position, position, _textPeer);\n                }\n            }\n            if (range == null)\n            {\n                throw new ArgumentException(SR.TextProvider_InvalidPoint);\n            }\n            return range;\n        }\n\n        /// <summary>\n        /// A text range that encloses the main text of the document.  Some auxillary text such as \n        /// headers, footnotes, or annotations may not be included. \n        /// </summary>\n        ITextRangeProvider ITextProvider.DocumentRange\n        {\n            get\n            {\n                return new TextRangeAdaptor(this, _textContainer.Start, _textContainer.End, _textPeer);\n            }\n        }\n\n        /// <summary>\n        /// True if the text container supports text selection. If the provider returns false then","sourceCodeStart":649,"sourceCodeEnd":685,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextAdaptor.cs#L649-L685","documentation":"TextAdaptor's ITextProvider.RangeFromPoint throws ArgumentException when no text position can be resolved for the given screen point — i.e., the point is not over any text of this provider, so no TextRangeAdaptor could be constructed.","triggerScenarios":"Calling TextPattern.RangeFromPoint with screen coordinates outside the rendered text (over margins, other controls, or off-screen), or with a point whose hit-testing yields no valid TextPosition in the container.","commonSituations":"Automation clients using stale window coordinates after a window move; hit-testing points over decorative or empty areas; coordinate conversion mistakes (client vs screen coordinates).","solutions":["Convert the point to correct screen coordinates relative to the control before calling RangeFromPoint.","Verify the point lies within the text provider's bounding rectangle (use BoundingRectangle first).","Catch ArgumentException and fall back to a degenerate document range or ignore the hit."],"exampleFix":"// before\nvar range = textPattern.RangeFromPoint(clientPoint);\n// after\nvar screenPoint = targetElement.PointToScreen(clientPoint);\nif (textProviderDocumentRange.GetBoundingRectangles().Any(r => ((Rect)r).Contains(screenPoint)))\n{ var range = textPattern.RangeFromPoint(screenPoint); }","handlingStrategy":"validation","validationCode":"var bounds = targetElement.BoundingRectangle;\nif (!bounds.Contains(screenPoint)) return; // point not over this text","typeGuard":"static bool PointOverText(Rect boundingRect, Point p) => boundingRect.Contains(p);","tryCatchPattern":"try { var r = textPattern.RangeFromPoint(screenPoint); }\ncatch (ArgumentException) { /* point not over text */ }","preventionTips":["Convert to screen coordinates before hit-testing","Check BoundingRectangle first","Refresh coordinates after window moves"],"tags":["wpf","ui-automation","text-pattern","argument-exception"],"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-21T21:30:21.729Z"}