{"record":{"id":"1c2f07b6b4e066eb","repo":"dotnet/wpf","slug":"0x80040206","errorCode":"0x80040206","errorMessage":"SR.TextStore_TS_E_NOLAYOUT","messagePattern":"SR\\.TextStore_TS_E_NOLAYOUT","errorType":"error_code","errorClass":"COMException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs","lineNumber":957,"sourceCode":"            GetVisualInfo(out source, out win32Window, out view);\n            compositionTarget = source.CompositionTarget;\n\n            // Convert to client coordinates.\n            SafeNativeMethods.ScreenToClient(new HandleRef(null, win32Window.Handle), ref point);\n\n            // Convert to mil measure units.\n            milPoint = new Point(point.x, point.y);\n            milPoint = compositionTarget.TransformFromDevice.Transform(milPoint);\n\n            // Convert to local coordinates.\n            GeneralTransform transform = compositionTarget.RootVisual.TransformToDescendant(RenderScope);\n            // REVIEW: should we throw if the point could not be transformed?\n            transform?.TryTransform(milPoint, out milPoint);\n\n            // Validate layout information on TextView\n            if (!view.Validate(milPoint))\n            {\n                throw new COMException(SR.TextStore_TS_E_NOLAYOUT, UnsafeNativeMethods.TS_E_NOLAYOUT);\n            }\n\n            // Do the hittest.\n            position = view.GetTextPositionFromPoint(milPoint, (flags & UnsafeNativeMethods.GetPositionFromPointFlags.GXFPF_NEAREST) != 0 /* snapToText */);\n            if (position == null)\n            {\n                // GXFPF_ROUND_NEAREST was clear and we didn't hit a char.\n                throw new COMException(SR.TextStore_TS_E_INVALIDPOINT, UnsafeNativeMethods.TS_E_INVALIDPOINT);\n            }\n\n            positionCP = position.CharOffset;\n            if ((flags & UnsafeNativeMethods.GetPositionFromPointFlags.GXFPF_ROUND_NEAREST) == 0)\n            {\n                // Check if the point is on the backward position of the TextPosition.\n                Rect rectCur;\n                Rect rectPrev;\n                Point milPointTopLeft;\n                Point milPointBottomRight;","sourceCodeStart":939,"sourceCodeEnd":975,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs#L939-L975","documentation":"TS_E_NOLAYOUT (0x80040206) is thrown from GetPositionFromPoint when the TextView cannot validate layout for the transformed point — WPF has no valid screen layout for the text, so a screen coordinate cannot be mapped to a text position. TSF defines this HRESULT exactly for 'layout information is not available'.","triggerScenarios":"ITextStoreACP::GetACPFromPoint (GetPositionFromPoint) called before the control's layout has been produced/validated: view.Validate(milPoint) returns false after transforming the POINT with the current transform.","commonSituations":"TSF composition/point queries arriving before the RichTextBox is rendered (not yet measured/arranged), after the control was removed from the visual tree, or while the window is minimized/hidden.","solutions":["Delay the text-service point query until the editor is loaded, rendered, and visible (IsLoaded/IsVisible true, layout complete).","Ensure the control is in a visible window and the visual tree, then retry; TSF clients typically retry after TS_E_NOLAYOUT.","If hit-testing is programmatically needed, force a layout pass (UpdateLayout) before requesting the position."],"exampleFix":"// before\nvar pos = GetPositionFromPoint(screenPoint); // may throw TS_E_NOLAYOUT before layout\n// after\nif (textBox.IsLoaded && textBox.IsVisible) { textBox.UpdateLayout(); var pos = GetPositionFromPoint(screenPoint); }","handlingStrategy":"retry","validationCode":"bool ready = editor.IsLoaded && editor.IsVisible; if (ready) editor.UpdateLayout(); // then issue the point query","typeGuard":null,"tryCatchPattern":"catch (COMException e) when (e.ErrorCode == unchecked((int)0x80040206)) { /* TS_E_NOLAYOUT: defer/retry after layout completes */ }","preventionTips":["Don't hit-test text before the control is rendered.","Force UpdateLayout before programmatic point-to-position queries.","Retry TS_E_NOLAYOUT after the next layout pass — TSF clients expect this pattern."],"tags":["wpf","tsf","layout","hit-test","com-interop"],"backgroundTag":"text-layout-unavailable","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"}