{"record":{"id":"fe8a1d1bfc76bf04","repo":"dotnet/wpf","slug":"0x80040209","errorCode":"0x80040209","errorMessage":"SR.TextStore_TS_E_READONLY","messagePattern":"SR\\.TextStore_TS_E_READONLY","errorType":"error_code","errorClass":"COMException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs","lineNumber":474,"sourceCode":"            }\n\n            nextIndex = navigator.CharOffset;\n\n            if (IsTracing)\n            {\n                IMECompositionTracer.Trace(this, IMECompositionTraceOp.GetText,\n                                            \"text:\", startIndex, endIndex, cchReq, charsCopied, new String(text, 0, charsCopied),\n                                            \"runs:\", cRunInfoReq, cRunInfoRcv,\n                                            \"next:\", nextIndex);\n            }\n        }\n\n        // See msdn's ITextStoreACP documentation for a full description.\n        public void SetText(UnsafeNativeMethods.SetTextFlags flags, int startIndex, int endIndex, char[] text, int cch, out UnsafeNativeMethods.TS_TEXTCHANGE change)\n        {\n            if (this.IsReadOnly)\n            {\n                throw new COMException(SR.TextStore_TS_E_READONLY, UnsafeNativeMethods.TS_E_READONLY);\n            }\n\n            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","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs#L456-L492","documentation":"TextStore.SetText (ITextStoreACP::SetText implementation) throws this COMException with HRESULT TS_E_READONLY (0x80040209) when the underlying text container is read-only. TSF cannot modify text in a read-only store, so the modification request is rejected with the standard TSF read-only error code.","triggerScenarios":"An IME/text service calls SetText while the WPF control (e.g. read-only TextBox/RichTextBox) reports IsReadOnly == true.","commonSituations":"User focuses an IME composition into a read-only text box; automation or test harness writing text into a read-only document; app sets TextBox.IsReadOnly while composition is active.","solutions":["Make the target control editable (set IsReadOnly=false) before text services attempt composition.","In the text service, check the TS_LF_READ-only status / document flags before calling SetText and fall back to not modifying text.","Catch COMException with HRESULT TS_E_READONLY and treat the edit as rejected rather than crashing."],"exampleFix":"// before\nstore.SetText(flags, start, end, chars, chars.Length, out change);\n// after\nif (!store.IsReadOnly)\n    store.SetText(flags, start, end, chars, chars.Length, out change);","handlingStrategy":"validation","validationCode":"if (!control.IsReadOnly) { store.SetText(flags, start, end, text, text.Length, out change); }","typeGuard":null,"tryCatchPattern":"try { store.SetText(...); } catch (COMException ex) when (ex.ErrorCode == unchecked((int)0x80040209)) { /* treat edit as rejected */ }","preventionTips":["Check IsReadOnly before any TSF write operation","Avoid switching IsReadOnly while IME composition is active","Handle TS_E_READONLY HRESULT explicitly in text services"],"tags":["wpf","tsf","ime","read-only"],"backgroundTag":"permission-denied","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"}