{"record":{"id":"60042acde7354582","repo":"dotnet/wpf","slug":"sr-documentreadonly","errorCode":null,"errorMessage":"SR.DocumentReadOnly","messagePattern":"SR\\.DocumentReadOnly","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequenceTextPointer.cs","lineNumber":226,"sourceCode":"        }\n\n        /// <summary>\n        /// <see cref=\"ITextPointer.GetFrozenPointer\"/>\n        /// </summary>\n        ITextPointer ITextPointer.GetFrozenPointer(LogicalDirection logicalDirection)\n        {\n            return TextPointerBase.GetFrozenPointer(this, logicalDirection);\n        }\n\n        /// <summary>\n        /// Inserts text at a specified position.\n        /// </summary>\n        /// <param name=\"textData\">\n        /// Text to insert.\n        /// </param>\n        void ITextPointer.InsertTextInRun(string textData)\n        {\n            throw new InvalidOperationException(SR.DocumentReadOnly);\n        }\n\n        /// <summary>\n        /// Removes content covered by a pair of positions.\n        /// </summary>\n        /// <param name=\"limit\">\n        /// Position following the last symbol to delete.  endPosition must be\n        /// scoped by the same text element as startPosition.\n        /// </param>\n        void ITextPointer.DeleteContentToPosition(ITextPointer limit)\n        {\n            throw new InvalidOperationException(SR.DocumentReadOnly);\n        }\n\n        // Candidate for replacing MoveToNextContextPosition for immutable TextPointer model\n        ITextPointer ITextPointer.GetNextContextPosition(LogicalDirection direction)\n        {\n            ITextPointer pointer = ((ITextPointer)this).CreatePointer();","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequenceTextPointer.cs#L208-L244","documentation":"DocumentSequenceTextPointer wraps a read-only document sequence, so the ITextPointer.InsertTextInRun implementation unconditionally throws InvalidOperationException with SR.DocumentReadOnly. FixedDocumentSequence content cannot be edited in place.","triggerScenarios":"Calling ITextPointer.InsertTextInRun on a pointer obtained from a FixedDocumentSequence/DocumentSequenceTextContainer, typically from text editing or IME composition code.","commonSituations":"Attempting programmatic text insertion into an XPS/FixedDocumentSequence view; TextEditor pipelines treating the sequence container as editable like a FlowDocument.","solutions":["Do not edit DocumentSequence content via text pointers; the document is immutable","Edit the underlying source documents (e.g., individual FlowDocuments) before generating the sequence","Catch InvalidOperationException and treat the sequence as read-only in the UI (disable editing affordances)"],"exampleFix":"// before\nptr.InsertTextInRun(\"text\"); // throws on FixedDocumentSequence\n// after\nif (ptr is DocumentSequenceTextPointer) { /* sequence is read-only; edit source document instead */ }\nelse { ptr.InsertTextInRun(\"text\"); }","handlingStrategy":"type-guard","validationCode":"if (pointer is DocumentSequenceTextPointer)\n    throw new InvalidOperationException(\"Document sequence is read-only; InsertTextInRun is not allowed\");","typeGuard":"bool IsEditablePointer(ITextPointer p) => p is not DocumentSequenceTextPointer;","tryCatchPattern":"try { ptr.InsertTextInRun(text); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"read-only\")) { /* disable editing UI */ }","preventionTips":["Disable editing commands when the viewer shows a FixedDocumentSequence/XPS","Edit source FlowDocuments instead of the composed sequence","Check pointer type before calling mutation APIs"],"tags":["wpf","documents","read-only","editing"],"backgroundTag":"document-read-only","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"}