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

  1. Implement ITypedDataObject on the custom IDataObject class
  2. Convert/wrap the foreign IDataObject into a WPF DataObject (new DataObject(legacyObject)) that supports typed retrieval
  3. Use untyped GetData(format) and cast the result manually when ITypedDataObject is unavailable
  4. 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

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


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)