dotnet/wpf · error · COMException
0x80070057
0x80070057
Error message
SR.TextStore_BadObject
What it means
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.
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.
Example fix
// before store.InsertEmbedded(flags, start, end, new DataObject(), out change); // after IComDataObject comData = /* COM IDataObject instance */; store.InsertEmbedded(flags, start, end, comData, out change);
Defensive patterns
Strategy: type-guard
Validate before calling
if (obj is IComDataObject data) { store.InsertEmbedded(flags, start, end, data, out change); } Type guard
bool IsComDataObject(object o) => o is IComDataObject;
Try / catch
try { store.InsertEmbedded(...); } catch (COMException ex) when (ex.ErrorCode == unchecked((int)0x80070057)) { /* wrong data object type */ } Prevention
- 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
When it happens
Trigger: A TSF client calls InsertEmbedded passing a managed System.Windows.DataObject, arbitrary object, or null instead of a COM IComDataObject/IDataObject instance.
Common situations: Interop code conflating managed DataObject with the COM IDataObject; passing the wrong data-object wrapper type across the TSF boundary.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/f61fd5f428ac5b70.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs:626
// Disable embedded object temporarily.
#if ENABLE_INK_EMBEDDING
if (!TextSelection.HasConcreteTextContainer)
{
throw new COMException(SR.TextStore_TS_E_FORMAT, UnsafeNativeMethods.TS_E_FORMAT);
}
TextContainer container;
TextPointer startPosition;
TextPointer endPosition;
IComDataObject data;
// The object must have IOldDataObject internface.
// The obj param of InsertEmbedded is IDataObject in Win32 definition.
data = obj as IComDataObject;
if (data == null)
{
throw new COMException(SR.TextStore_BadObject, NativeMethods.E_INVALIDARG);
}
container = (TextContainer)this.TextContainer;
startPosition = container.CreatePointerAtOffset(startIndex, LogicalDirection.Backward);
endPosition = container.CreatePointerAtOffset(endIndex, LogicalDirection.Forward);
InsertEmbeddedAtRange(startPosition, endPosition, data, out change);
#else
throw new COMException(SR.TextStore_TS_E_FORMAT, UnsafeNativeMethods.TS_E_FORMAT);
#endif
}
// See msdn's ITextStoreACP documentation for a full description.
public void InsertTextAtSelection(UnsafeNativeMethods.InsertAtSelectionFlags flags, char[] text, int cch, out int startIndex, out int endIndex, out UnsafeNativeMethods.TS_TEXTCHANGE change)
{
ITextPointer startNavigator;
ITextPointer endNavigator;View on GitHub (pinned to 81131a70a4)