{"record":{"id":"f61fd5f428ac5b70","repo":"dotnet/wpf","slug":"0x80070057","errorCode":"0x80070057","errorMessage":"SR.TextStore_BadObject","messagePattern":"SR\\.TextStore_BadObject","errorType":"error_code","errorClass":"COMException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs","lineNumber":626,"sourceCode":"\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);\n            endPosition = container.CreatePointerAtOffset(endIndex, LogicalDirection.Forward);\n\n            InsertEmbeddedAtRange(startPosition, endPosition, data, out change);\n#else\n            throw new COMException(SR.TextStore_TS_E_FORMAT, UnsafeNativeMethods.TS_E_FORMAT);\n#endif\n        }\n\n        // See msdn's ITextStoreACP documentation for a full description.\n        public void InsertTextAtSelection(UnsafeNativeMethods.InsertAtSelectionFlags flags, char[] text, int cch, out int startIndex, out int endIndex, out UnsafeNativeMethods.TS_TEXTCHANGE change)\n        {\n            ITextPointer startNavigator;\n            ITextPointer endNavigator;","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs#L608-L644","documentation":"InsertEmbedded's obj parameter must implement IComDataObject (the COM IDataObject). TextStore casts with 'obj as IComDataObject' and throws COMException with E_INVALIDARG (0x80070057) and SR.TextStore_BadObject when the cast fails, i.e. the caller passed an object that is not a COM data object.","triggerScenarios":"A TSF client calls InsertEmbedded passing a managed System.Windows.DataObject, arbitrary object, or null instead of a COM IComDataObject/IDataObject instance.","commonSituations":"Interop code conflating managed DataObject with the COM IDataObject; passing the wrong data-object wrapper type across the TSF boundary.","solutions":["Pass an object implementing IComDataObject (COM IDataObject) to InsertEmbedded.","Wrap managed data with the appropriate COM-callable wrapper before the call.","Null-check and type-check the object client-side before invoking InsertEmbedded."],"exampleFix":"// before\nstore.InsertEmbedded(flags, start, end, new DataObject(), out change);\n// after\nIComDataObject comData = /* COM IDataObject instance */;\nstore.InsertEmbedded(flags, start, end, comData, out change);","handlingStrategy":"type-guard","validationCode":"if (obj is IComDataObject data) { store.InsertEmbedded(flags, start, end, data, out change); }","typeGuard":"bool IsComDataObject(object o) => o is IComDataObject;","tryCatchPattern":"try { store.InsertEmbedded(...); } catch (COMException ex) when (ex.ErrorCode == unchecked((int)0x80070057)) { /* wrong data object type */ }","preventionTips":["Always pass COM IDataObject (IComDataObject), never managed DataObject","Null-check and type-check before interop calls","Keep managed/COM data-object wrappers distinct in your API"],"tags":["wpf","tsf","interop","type-mismatch"],"backgroundTag":"type-mismatch","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"}