{"record":{"id":"b76c9f791487cc11","repo":"dotnet/wpf","slug":"sr-itypedataobject-not-implemented","errorCode":null,"errorMessage":"SR.ITypeDataObject_Not_Implemented","messagePattern":"SR\\.ITypeDataObject_Not_Implemented","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DataObjectExtensions.cs","lineNumber":21,"sourceCode":"\n#nullable enable\n\nusing System.Diagnostics.CodeAnalysis;\n\nnamespace System.Windows;\n\n/// <summary>\n///  Extension methods for data objects.\n/// </summary>\npublic static class DataObjectExtensions\n{\n    private static ITypedDataObject GetTypedDataObjectOrThrow(IDataObject dataObject)\n    {\n        ArgumentNullException.ThrowIfNull(dataObject);\n\n        if (dataObject is not ITypedDataObject typed)\n        {\n            throw new NotSupportedException(string.Format(\n                SR.ITypeDataObject_Not_Implemented,\n                dataObject.GetType().FullName));\n        }\n\n        return typed;\n    }\n\n    /// <inheritdoc cref=\"ITypedDataObject.TryGetData{T}(out T)\"/>\n    /// <exception cref=\"NotSupportedException\">if the <paramref name=\"dataObject\"/> does not implement <see cref=\"ITypedDataObject\" />.</exception>\n    /// <exception cref=\"ArgumentNullException\">if the <paramref name=\"dataObject\"/> is <see langword=\"null\"/></exception>\n    public static bool TryGetData<T>(\n        this IDataObject dataObject,\n        [NotNullWhen(true), MaybeNullWhen(false)] out T data) =>\n            GetTypedDataObjectOrThrow(dataObject).TryGetData(out data);\n\n    /// <inheritdoc cref=\"ITypedDataObject.TryGetData{T}(string, out T)\"/>\n    /// <exception cref=\"NotSupportedException\">if the <paramref name=\"dataObject\"/> does not implement <see cref=\"ITypedDataObject\" />.</exception>\n    /// <exception cref=\"ArgumentNullException\">if the <paramref name=\"dataObject\"/> is <see langword=\"null\"/></exception>","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DataObjectExtensions.cs#L3-L39","documentation":"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.","triggerScenarios":"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.","commonSituations":"Clipboard interop with external apps yielding raw IDataObject wrappers; third-party or hand-rolled IDataObject implementations that predate ITypedDataObject; unit-test fakes of IDataObject.","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"],"exampleFix":"// before\nvar text = foreignDataObject.TryGetData<string>(DataFormats.StringFormat);\n// after\nif (foreignDataObject is ITypedDataObject typed)\n{\n    var text = typed.TryGetData<string>(DataFormats.StringFormat);\n}\nelse\n{\n    var obj = foreignDataObject.GetData(DataFormats.StringFormat) as string;\n}","handlingStrategy":"type-guard","validationCode":"bool supportsTyped = dataObject is ITypedDataObject;","typeGuard":"static bool SupportsTypedData(IDataObject o) => o is ITypedDataObject;","tryCatchPattern":"try\n{\n    var value = dataObject.TryGetData<string>(DataFormats.StringFormat);\n}\ncatch (NotSupportedException ex)\n{\n    // dataObject does not implement ITypedDataObject; fall back to GetData\n}","preventionTips":["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"],"tags":["wpf","clipboard","type-mismatch","interface"],"backgroundTag":"incompatible-source-type","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"}