dotnet/wpf · error · COMException
0x80040207
0x80040207
Error message
SR.TextStore_TS_E_INVALIDPOINT
What it means
TS_E_INVALIDPOINT (0x80040207) is thrown from GetPositionFromPoint when the point falls outside any character: layout was valid, but GetTextPositionFromPoint returned null because GXFPF_ROUND_NEAREST was clear and the point did not hit a character. It is the TSF HRESULT for 'the point is not over text'.
Solutions
- Pass the GXFPF_ROUND_NEAREST flag so TSF rounds to the nearest character instead of failing.
- Verify the client coordinate conversion (screen-to-client, DPI scaling) before hit-testing.
- Only issue point queries for points inside the rendered text rectangle; clamp or reject outside points upstream.
Example fix
// before var flags = 0; // GXFPF_ROUND_NEAREST clear -> point must hit a char exactly // after var flags = UnsafeNativeMethods.GetPositionFromPointFlags.GXFPF_ROUND_NEAREST; // snap to nearest char
Defensive patterns
Strategy: validation
Validate before calling
// Only hit-test points inside the editor's text area; convert screen->client with DPI awareness first. var pt = editor.PointFromScreen(screenPoint); bool inside = editor.RenderSize.Width > pt.X && pt.X >= 0 && editor.RenderSize.Height > pt.Y && pt.Y >= 0;
Try / catch
catch (COMException e) when (e.ErrorCode == unchecked((int)0x80040207)) { /* point not over text: ignore or retry with GXFPF_ROUND_NEAREST */ } Prevention
- Set GXFPF_ROUND_NEAREST when exact character hits aren't required.
- Validate coordinates (DPI, window origin) before querying.
- Treat points over margins/blank areas as no-ops.
When it happens
Trigger: ITextStoreACP::GetACPFromPoint called with a screen point that misses all text and without the GXFPF_ROUND_NEAREST flag (and GXFPF_NEAREST not producing a snap), so no text position can be returned.
Common situations: IME candidate/phrase-boundary clicks in empty areas beside text (margins, blank lines' trailing space); coordinate conversion mismatches (per-monitor DPI, wrong window origin) putting points off the text surface.
Related errors
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/55921db319c841bd.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs:965
milPoint = compositionTarget.TransformFromDevice.Transform(milPoint);
// Convert to local coordinates.
GeneralTransform transform = compositionTarget.RootVisual.TransformToDescendant(RenderScope);
// REVIEW: should we throw if the point could not be transformed?
transform?.TryTransform(milPoint, out milPoint);
// Validate layout information on TextView
if (!view.Validate(milPoint))
{
throw new COMException(SR.TextStore_TS_E_NOLAYOUT, UnsafeNativeMethods.TS_E_NOLAYOUT);
}
// Do the hittest.
position = view.GetTextPositionFromPoint(milPoint, (flags & UnsafeNativeMethods.GetPositionFromPointFlags.GXFPF_NEAREST) != 0 /* snapToText */);
if (position == null)
{
// GXFPF_ROUND_NEAREST was clear and we didn't hit a char.
throw new COMException(SR.TextStore_TS_E_INVALIDPOINT, UnsafeNativeMethods.TS_E_INVALIDPOINT);
}
positionCP = position.CharOffset;
if ((flags & UnsafeNativeMethods.GetPositionFromPointFlags.GXFPF_ROUND_NEAREST) == 0)
{
// Check if the point is on the backward position of the TextPosition.
Rect rectCur;
Rect rectPrev;
Point milPointTopLeft;
Point milPointBottomRight;
ITextPointer positionCur = position.CreatePointer(LogicalDirection.Backward);
ITextPointer positionPrev = position.CreatePointer(LogicalDirection.Forward);
positionPrev.MoveToNextInsertionPosition(LogicalDirection.Backward);
rectCur = view.GetRectangleFromTextPosition(positionCur);
rectPrev = view.GetRectangleFromTextPosition(positionPrev);
View on GitHub (pinned to 81131a70a4)