dotnet/wpf · error · NotSupportedException
SR.ITypeDataObject_Not_Implemented
Error message
SR.ITypeDataObject_Not_Implemented
What it means
DataObjectExtensions.TryGetData (and friends) require the IDataObject to implement ITypedDataObject so strongly-typed retrieval is possible. GetTypedDataObjectOrThrow throws NotSupportedException with SR.ITypeDataObject_Not_Implemented, naming the concrete type, when a plain IDataObject is passed.
Solutions
- Implement ITypedDataObject on the custom IDataObject class
- Convert/wrap the foreign IDataObject into a WPF DataObject (new DataObject(legacyObject)) that supports typed retrieval
- Use untyped GetData(format) and cast the result manually when ITypedDataObject is unavailable
- Pattern-match `if (dataObject is ITypedDataObject)` before calling TryGetData
Example fix
// before
var text = foreignDataObject.TryGetData<string>(DataFormats.StringFormat);
// after
if (foreignDataObject is ITypedDataObject typed)
{
var text = typed.TryGetData<string>(DataFormats.StringFormat);
}
else
{
var obj = foreignDataObject.GetData(DataFormats.StringFormat) as string;
} Defensive patterns
Strategy: type-guard
Validate before calling
bool supportsTyped = dataObject is ITypedDataObject;
Type guard
static bool SupportsTypedData(IDataObject o) => o is ITypedDataObject;
Try / catch
try
{
var value = dataObject.TryGetData<string>(DataFormats.StringFormat);
}
catch (NotSupportedException ex)
{
// dataObject does not implement ITypedDataObject; fall back to GetData
} Prevention
- Pattern-match ITypedDataObject before calling TryGetData
- Implement ITypedDataObject in custom IDataObject classes
- Wrap legacy/OLE IDataObject in new DataObject(...) to gain typed access
- Use untyped GetData + cast for foreign data objects
When it happens
Trigger: Calling dataObject.TryGetData<T>() on an IDataObject that is not ITypedDataObject — e.g. a custom IDataObject implementation, an OLE/Win32 interop wrapper, or a legacy DataObject from another layer.
Common situations: Clipboard interop with external apps yielding raw IDataObject wrappers; third-party or hand-rolled IDataObject implementations that predate ITypedDataObject; unit-test fakes of IDataObject.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- The parameter must implement interface
- The type of this parameter does not support a required…
- ' ' is not a Visual or Visual3D.
- 0x80070057
- Animation_AnimationTimelineTypeMismatch
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/b76c9f791487cc11.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DataObjectExtensions.cs:21
#nullable enable
using System.Diagnostics.CodeAnalysis;
namespace System.Windows;
/// <summary>
/// Extension methods for data objects.
/// </summary>
public static class DataObjectExtensions
{
private static ITypedDataObject GetTypedDataObjectOrThrow(IDataObject dataObject)
{
ArgumentNullException.ThrowIfNull(dataObject);
if (dataObject is not ITypedDataObject typed)
{
throw new NotSupportedException(string.Format(
SR.ITypeDataObject_Not_Implemented,
dataObject.GetType().FullName));
}
return typed;
}
/// <inheritdoc cref="ITypedDataObject.TryGetData{T}(out T)"/>
/// <exception cref="NotSupportedException">if the <paramref name="dataObject"/> does not implement <see cref="ITypedDataObject" />.</exception>
/// <exception cref="ArgumentNullException">if the <paramref name="dataObject"/> is <see langword="null"/></exception>
public static bool TryGetData<T>(
this IDataObject dataObject,
[NotNullWhen(true), MaybeNullWhen(false)] out T data) =>
GetTypedDataObjectOrThrow(dataObject).TryGetData(out data);
/// <inheritdoc cref="ITypedDataObject.TryGetData{T}(string, out T)"/>
/// <exception cref="NotSupportedException">if the <paramref name="dataObject"/> does not implement <see cref="ITypedDataObject" />.</exception>
/// <exception cref="ArgumentNullException">if the <paramref name="dataObject"/> is <see langword="null"/></exception>View on GitHub (pinned to 81131a70a4)