{"record":{"id":"3b6dd40aa6d25e4f","repo":"dotnet/wpf","slug":"0x8004020a","errorCode":"0x8004020a","errorMessage":"SR.TextStore_TS_E_FORMAT","messagePattern":"SR\\.TextStore_TS_E_FORMAT","errorType":"error_code","errorClass":"COMException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs","lineNumber":613,"sourceCode":"            {\n                insertable = false;\n            }\n#endif\n        }\n\n        // See msdn's ITextStoreACP documentation for a full description.\n        public void InsertEmbedded(UnsafeNativeMethods.InsertEmbeddedFlags flags, int startIndex, int endIndex, object obj, out UnsafeNativeMethods.TS_TEXTCHANGE change)\n        {\n            if (IsReadOnly)\n            {\n                throw new COMException(SR.TextStore_TS_E_READONLY, UnsafeNativeMethods.TS_E_READONLY);\n            }\n\n            // Disable embedded object temporarily.\n#if ENABLE_INK_EMBEDDING\n            if (!TextSelection.HasConcreteTextContainer)\n            {\n                throw new COMException(SR.TextStore_TS_E_FORMAT, UnsafeNativeMethods.TS_E_FORMAT);\n            }\n\n            TextContainer container;\n            TextPointer startPosition;\n            TextPointer endPosition;\n            IComDataObject data;\n\n            // The object must have IOldDataObject internface.\n            // The obj param of InsertEmbedded is IDataObject in Win32 definition.\n            data = obj as IComDataObject;\n            if (data == null)\n            {\n                throw new COMException(SR.TextStore_BadObject, NativeMethods.E_INVALIDARG);\n            }\n\n            container = (TextContainer)this.TextContainer;\n\n            startPosition = container.CreatePointerAtOffset(startIndex, LogicalDirection.Backward);","sourceCodeStart":595,"sourceCodeEnd":631,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs#L595-L631","documentation":"When compiled with ENABLE_INK_EMBEDDING, InsertEmbedded requires the text selection to have a concrete text container (TextSelection.HasConcreteTextContainer); if not, it throws COMException TS_E_FORMAT (0x8004020a) because the target cannot accept embedded-object format. Without that build flag the same call path throws TS_E_FORMAT unconditionally (see 2869).","triggerScenarios":"InsertEmbedded called when the TextSelection does not back a concrete TextContainer (e.g. non-concrete/virtual selection), inside the ENABLE_INK_EMBEDDING code path.","commonSituations":"TSF clients inserting embedded objects into WPF selections that do not represent an editable RichTextBox-style document (ink embedding is effectively disabled in WPF).","solutions":["Do not attempt embedded-object insertion into WPF text controls; TS_E_FORMAT indicates unsupported format.","Convert the content to plain text and use SetText/InsertTextAtSelection instead.","Catch COMException with HRESULT TS_E_FORMAT and fall back to plain-text insertion."],"exampleFix":"// before\nstore.InsertEmbedded(flags, start, end, dataObject, out change);\n// after: fall back to text\nstore.SetText(flags, start, end, textChars, textChars.Length, out change);","handlingStrategy":"try-catch","validationCode":"if (!TextSelection.HasConcreteTextContainer) { /* target cannot accept embedded format; use text instead */ }","typeGuard":null,"tryCatchPattern":"try { store.InsertEmbedded(...); } catch (COMException ex) when (ex.ErrorCode == unchecked((int)0x8004020a)) { /* fall back to plain text insert */ }","preventionTips":["Do not insert embedded objects into WPF text controls","Convert embedded content to text first","Handle TS_E_FORMAT as 'unsupported format'"],"tags":["wpf","tsf","embedded-objects","unsupported-format"],"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"}