{"record":{"id":"38b862b60b2df164","repo":"dotnet/wpf","slug":"sr-format-sr-richedittextpatternhasnochildren-gettype","errorCode":null,"errorMessage":"SR.Format(SR.RichEditTextPatternHasNoChildren, GetType().FullName)","messagePattern":"SR\\.Format\\(SR\\.RichEditTextPatternHasNoChildren, GetType\\(\\)\\.FullName\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsRichEdit.cs","lineNumber":260,"sourceCode":"            else\n                return new ITextRangeProvider[] { new WindowsRichEditRange(range, this) };\n        }\n\n        ITextRangeProvider [] ITextProvider.GetVisibleRanges()\n        {\n            ITextRange range = GetVisibleRange();\n\n            if (range == null)\n                return Array.Empty<ITextRangeProvider>();\n            else\n                return new ITextRangeProvider[] { new WindowsRichEditRange(range, this) };\n        }\n\n        ITextRangeProvider ITextProvider.RangeFromChild(IRawElementProviderSimple childElement)\n        {\n            // we don't have any children so this call must be in error.\n            // if we implement children for hyperlinks and embedded objects then we'll need to change this.\n            throw new InvalidOperationException(SR.Format(SR.RichEditTextPatternHasNoChildren, GetType().FullName));\n        }\n\n        ITextRangeProvider ITextProvider.RangeFromPoint(Point screenLocation)\n        {\n            // we must have called EnsureTextDocument() before arriving here.\n            Debug.Assert(_document != null);\n\n            // TextPattern has verified that the point is inside our client area so we don't need to check for that.\n\n            // get the degenerate range at the point\n            // we're assuming ITextDocument::RangeFromPoint always returns a degenerate range\n            ITextRange range = _document.RangeFromPoint((int)screenLocation.X, (int)screenLocation.Y);\n            Debug.Assert(range.Start == range.End);\n\n            // if you wanted to get the character under the point instead of the degenerate range nearest\n            // the point, then you would add:\n\n            //// if the point is within the character to the right then expand the degenerate range to","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsRichEdit.cs#L242-L278","documentation":"The rich edit control's ITextProvider exposes one whole-document text range and no child elements (hyperlinks/embedded objects are not exposed as children). RangeFromChild is therefore meaningless for this element and unconditionally throws InvalidOperationException(SR.RichEditTextPatternHasNoChildren, GetType().FullName), naming the concrete proxy type in the message.","triggerScenarios":"Calling ITextProvider.RangeFromChild(childElement) on a WindowsRichEdit-based Text pattern with any childElement argument — the call can never succeed.","commonSituations":"Generic Text-pattern helper code that walks UIA elements by calling RangeFromChild for every parent element; passing hyperlink or embedded-object automation elements assuming they are children of the rich edit.","solutions":["Use RangeFromPoint or DocumentRange / text-unit methods (Move, FindText) instead of RangeFromChild on rich edits","Guard: only call RangeFromChild for providers that actually expose children; check the element's supported pattern/control type first","Restructure automation to search text via FindText on the document range rather than child traversal"],"exampleFix":"// before\nvar range = textPattern.RangeFromChild(childElement); // always throws for RichEdit\n// after\nif (isRichEdit)\n    var range = textPattern.DocumentRange.FindText(searchText, false, false);\nelse\n    var range = textPattern.RangeFromChild(childElement);","handlingStrategy":"fallback","validationCode":"var range = textPattern is RichEditTextPattern ? null : childElement != null ? textPattern.RangeFromChild(childElement) : null;","typeGuard":"bool SupportsRangeFromChild(TextPattern tp) => !(tp.GetType().Name.Contains(\"RichEdit\"));","tryCatchPattern":"try { range = textPattern.RangeFromChild(child); } catch (InvalidOperationException) { range = textPattern.DocumentRange.FindText(text, false, false); }","preventionTips":["Never call RangeFromChild on rich edit text providers — they expose no children","Use DocumentRange.FindText or RangeFromPoint for locating text","Write generic text-pattern helpers that tolerate InvalidOperationException from RangeFromChild"],"tags":["uiautomation","text-pattern","richedit","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}