{"record":{"id":"de8f223978ac24df","repo":"dotnet/wpf","slug":"sr-fixeddocumentreadonly","errorCode":null,"errorMessage":"SR.FixedDocumentReadonly","messagePattern":"SR\\.FixedDocumentReadonly","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextPointer.cs","lineNumber":495,"sourceCode":"        /// </summary>\n        bool ITextPointer.MoveToNextInsertionPosition(LogicalDirection direction)\n        {\n            return TextPointerBase.MoveToNextInsertionPosition(this, direction);\n        }\n\n        //\n        // TextContainer modification methods. Disabled by design.\n        //\n        // This is readonly Text OM. All modification methods returns false\n        //\n\n        /// <summary>\n        /// </summary>\n        void ITextPointer.InsertTextInRun(string textData)\n        {\n            ArgumentNullException.ThrowIfNull(textData);\n\n            throw new InvalidOperationException(SR.FixedDocumentReadonly);\n        }\n\n        /// <summary>\n        /// <see cref=\"ITextPointer.DeleteContentToPosition\"/>\n        /// </summary>\n        void ITextPointer.DeleteContentToPosition(ITextPointer limit)\n        {\n            throw new InvalidOperationException(SR.FixedDocumentReadonly);\n        }\n\n        /// <summary>\n        /// <see cref=\"ITextPointer.ValidateLayout\"/>\n        /// </summary>\n        bool ITextPointer.ValidateLayout()\n        {\n            return TextPointerBase.ValidateLayout(this, ((ITextPointer)this).TextContainer.TextView);\n        }\n","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextPointer.cs#L477-L513","documentation":"FixedTextPointer is a read-only pointer over a fixed document; inserting text into the text run at the pointer is not a supported mutation. InsertTextInRun unconditionally throws InvalidOperationException(SR.FixedDocumentReadonly) regardless of the supplied string (after a null check).","triggerScenarios":"Calling ITextPointer.InsertTextInRun on any FixedTextPointer, at any position, with any non-null string.","commonSituations":"Generic text-editor logic (designed for RichTextBox/FlowDocument editing) invoked against a FixedDocument view, e.g. IME input, spell-check correction or programmatic text substitution routed through a TextNavigator over fixed content.","solutions":["Do not attempt text edits on fixed documents; convert to an editable representation (e.g. FlowDocument) if editing is required","Guard edits with a capability check on the container (fixed documents are immutable) before calling InsertTextInRun","Catch InvalidOperationException and surface a read-only message to the user or disable editing UI","Perform content changes at the document/package level (XPS package regeneration) instead of via ITextPointer"],"exampleFix":"// before\ntextPointer.InsertTextInRun(\"new text\"); // always throws\n// after\nbool isReadOnly = textPointer is FixedTextPointer;\nif (!isReadOnly) textPointer.InsertTextInRun(\"new text\");","handlingStrategy":"validation","validationCode":"if (pointer is System.Windows.Documents.FixedTextPointer)\n    throw new NotSupportedException(\"Fixed documents are read-only; cannot insert text.\");","typeGuard":"bool CanEdit(System.Windows.Documents.ITextPointer p) => p is not System.Windows.Documents.FixedTextPointer;","tryCatchPattern":null,"preventionTips":["Check read-only status before any edit call","Disable editing UI when viewing fixed documents","Perform edits on FlowDocument copies, not fixed content"],"tags":["wpf","documents","read-only"],"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"}