dotnet/wpf · error · ArgumentException
SR.TextProvider_InvalidPoint
Error message
SR.TextProvider_InvalidPoint
What it means
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.
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.
Example fix
// before
var range = textPattern.RangeFromPoint(clientPoint);
// after
var screenPoint = targetElement.PointToScreen(clientPoint);
if (textProviderDocumentRange.GetBoundingRectangles().Any(r => ((Rect)r).Contains(screenPoint)))
{ var range = textPattern.RangeFromPoint(screenPoint); } Defensive patterns
Strategy: validation
Validate before calling
var bounds = targetElement.BoundingRectangle; if (!bounds.Contains(screenPoint)) return; // point not over this text
Type guard
static bool PointOverText(Rect boundingRect, Point p) => boundingRect.Contains(p);
Try / catch
try { var r = textPattern.RangeFromPoint(screenPoint); }
catch (ArgumentException) { /* point not over text */ } Prevention
- Convert to screen coordinates before hit-testing
- Check BoundingRectangle first
- Refresh coordinates after window moves
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.PropertyNotSupported
- SR.TextProvider_InvalidChildElement
- SR.TextProvider_TextSelectionNotSupported
- SR.TextRangeProvider_WrongTextRange
- ArgumentOutOfRangeException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/8c727bd33900d94d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextAdaptor.cs:667
/// if they are not.</param>
/// <returns>A degenerate range nearest the specified location.</returns>
ITextRangeProvider ITextProvider.RangeFromPoint(Point location)
{
TextRangeAdaptor range = null;
ITextView textView = GetUpdatedTextView();
if (textView != null)
{
// Convert the screen point to the element space coordinates.
location = ScreenToClient(location, textView.RenderScope);
ITextPointer position = textView.GetTextPositionFromPoint(location, true);
if (position != null)
{
range = new TextRangeAdaptor(this, position, position, _textPeer);
}
}
if (range == null)
{
throw new ArgumentException(SR.TextProvider_InvalidPoint);
}
return range;
}
/// <summary>
/// A text range that encloses the main text of the document. Some auxillary text such as
/// headers, footnotes, or annotations may not be included.
/// </summary>
ITextRangeProvider ITextProvider.DocumentRange
{
get
{
return new TextRangeAdaptor(this, _textContainer.Start, _textContainer.End, _textPeer);
}
}
/// <summary>
/// True if the text container supports text selection. If the provider returns false thenView on GitHub (pinned to 81131a70a4)