{"record":{"id":"ad36b22171463c4a","repo":"dotnet/wpf","slug":"0x80004005","errorCode":"0x80004005","errorMessage":"SR.TextStore_CompositionRejected","messagePattern":"SR\\.TextStore_CompositionRejected","errorType":"error_code","errorClass":"COMException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs","lineNumber":495,"sourceCode":"            if (IsTracing)\n            {\n                IMECompositionTracer.Trace(this, IMECompositionTraceOp.BSetText,\n                                            \"text:\", startIndex, endIndex, cch, new String(text, 0, cch));\n            }\n\n            ITextPointer start;\n            ITextPointer end;\n\n            GetNormalizedRange(startIndex, endIndex, out start, out end);\n\n            while (start != null && TextPointerBase.IsBeforeFirstTable(start))\n            {\n                start = start.GetNextInsertionPosition(LogicalDirection.Forward);\n            }\n\n            if (start == null)\n            {\n                throw new COMException(SR.TextStore_CompositionRejected, NativeMethods.E_FAIL);\n            }\n\n            if (start.CompareTo(end) > 0)\n            {\n                end = start;\n            }\n\n            string filteredText = FilterCompositionString(new string(text), start.GetOffsetToPosition(end)); // does NOT filter MaxLength.\n            if (filteredText == null)\n            {\n                throw new COMException(SR.TextStore_CompositionRejected, NativeMethods.E_FAIL);\n            }\n\n            // Openes a composition undo unit for the composition undo.\n            CompositionParentUndoUnit unit = OpenCompositionUndoUnit();\n            UndoCloseAction undoCloseAction = UndoCloseAction.Rollback;\n\n            try","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs#L477-L513","documentation":"During StartComposition/text-insert handling, TextStore computes the insertion range; if walking to the next insertion position yields a null start pointer, the composition cannot be placed anywhere valid and is rejected with E_FAIL (0x80004005) using SR.TextStore_CompositionRejected.","triggerScenarios":"An IME calls SetText/InsertTextAtSelection path in TextStore at a position where GetNextInsertionPosition(LogicalDirection.Forward) returns null (e.g. at document end with no valid insertion point), so start == null.","commonSituations":"Composition into a degenerate or empty document range; text container in a state where no insertion position exists (fully truncated content, MaxLength constraints producing an empty valid range).","solutions":["Ensure the control has a valid, editable insertion position before starting composition (focus an editable caret position).","Relax MaxLength/character filtering constraints that can leave no valid insertion point.","In the text service, catch COMException with E_FAIL and cancel the composition gracefully."],"exampleFix":"// caller-side guard\nvar start = range.GetNextInsertionPosition(LogicalDirection.Forward);\nif (start != null) store.SetText(flags, offset1, offset2, text, text.Length, out change);","handlingStrategy":"try-catch","validationCode":"var insertion = range.GetNextInsertionPosition(LogicalDirection.Forward); if (insertion == null) { /* no valid insertion point; skip composition */ }","typeGuard":"bool HasInsertionPosition(TextPointer p) => p?.GetNextInsertionPosition(LogicalDirection.Forward) != null;","tryCatchPattern":"try { /* composition path */ } catch (COMException ex) when (ex.ErrorCode == unchecked((int)0x80004005)) { /* cancel composition */ }","preventionTips":["Ensure caret is at a valid editable position before composition","Avoid degenerate/empty ranges in composition targets","Keep MaxLength constraints permissive enough for a valid insertion point"],"tags":["wpf","tsf","ime","composition"],"backgroundTag":"internal-invariant-violation","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"}