{"record":{"id":"2856bab90c0a9a83","repo":"dotnet/wpf","slug":"sr-dataobject-dataformatnotpresentondataobject","errorCode":null,"errorMessage":"SR.DataObject_DataFormatNotPresentOnDataObject","messagePattern":"SR\\.DataObject_DataFormatNotPresentOnDataObject","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DataObjectPastingEventArgs.cs","lineNumber":60,"sourceCode":"        /// as a candidate for applying in Paste operation.\n        /// An application can change this choice after inspecting\n        /// the content of data object.\n        /// </param>\n        public DataObjectPastingEventArgs(IDataObject dataObject, bool isDragDrop, string formatToApply) //\n            : base(System.Windows.DataObject.PastingEvent, isDragDrop)\n        {\n            ArgumentNullException.ThrowIfNull(dataObject);\n\n            ArgumentNullException.ThrowIfNull(formatToApply);\n\n            if (formatToApply == string.Empty)\n            {\n                throw new ArgumentException(SR.DataObject_EmptyFormatNotAllowed);\n            }\n\n            if (!dataObject.GetDataPresent(formatToApply))\n            {\n                throw new ArgumentException(SR.Format(SR.DataObject_DataFormatNotPresentOnDataObject, formatToApply));\n            }\n\n            _originalDataObject = dataObject;\n            _dataObject = dataObject;\n            _formatToApply = formatToApply;\n        }\n\n        #endregion Constructors\n\n        //------------------------------------------------------\n        //\n        //  Public Properties\n        //\n        //------------------------------------------------------\n\n        #region Public Properties\n\n        /// <summary>","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DataObjectPastingEventArgs.cs#L42-L78","documentation":"The DataObjectPastingEventArgs constructor throws ArgumentException when the supplied formatToApply is not present on the supplied dataObject, as verified by dataObject.GetDataPresent(formatToApply). The args object's contract is that FormatToApply names a format the DataObject actually contains; otherwise consumers of the Pasting event would try to read data that does not exist.","triggerScenarios":"new DataObjectPastingEventArgs(dataObject, isInDragDrop, formatToApply) where dataObject.GetDataPresent(formatToApply) returns false — e.g. the format was set with autoConvert formats excluded, or the format name is misspelled/differs in case.","commonSituations":"Passing a DataFormats constant the clipboard object never carried (e.g. Bitmap when only Text exists); building a DataObject in code and forgetting AddData for the named format; format auto-conversion differences between .NET versions.","solutions":["Add the data under that format: dataObject.SetData(formatToApply, value) before constructing args","Choose a format from dataObject.GetFormats() that actually exists","Verify the exact format string with dataObject.GetDataPresent(formatToApply) before constructing"],"exampleFix":"// before\nvar args = new DataObjectPastingEventArgs(dataObject, false, DataFormats.Html);\n// after\nif (dataObject.GetDataPresent(DataFormats.Html))\n{\n    var args = new DataObjectPastingEventArgs(dataObject, false, DataFormats.Html);\n}","handlingStrategy":"validation","validationCode":"if (formatToApply == null || !dataObject.GetDataPresent(formatToApply)) throw new ArgumentException($\"Format '{formatToApply}' is not present on the data object.\", nameof(formatToApply));","typeGuard":"bool HasFormat(IDataObject data, string format) => data.GetDataPresent(format);","tryCatchPattern":"try { var args = new DataObjectPastingEventArgs(dataObject, false, format); }\ncatch (ArgumentException) { format = dataObject.GetFormats().FirstOrDefault(); }","preventionTips":["Pick formats from dataObject.GetFormats(), not hardcoded constants","Call SetData before constructing paste event args","Log GetFormats() output when debugging format mismatches"],"tags":["wpf","argumentexception","clipboard","data-format"],"backgroundTag":"invalid-argument-value","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"}