{"record":{"id":"8e0c7a723f9ed1a3","repo":"dotnet/wpf","slug":"sr-dataobject-emptyformatnotallowed","errorCode":null,"errorMessage":"SR.DataObject_EmptyFormatNotAllowed","messagePattern":"SR\\.DataObject_EmptyFormatNotAllowed","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DataFormat.cs","lineNumber":22,"sourceCode":"using System.Private.Windows.Ole;\n\nnamespace System.Windows;\n\n/// <summary>\n///  Represents a data format type.\n/// </summary>\npublic sealed class DataFormat : IDataFormat<DataFormat>\n{\n    /// <summary>\n    ///  Initializes a new instance of the DataFormat class and specifies format name and id.\n    /// </summary>\n    public DataFormat(string name, int id)\n    {\n        ArgumentNullException.ThrowIfNull(name);\n\n        if (name.Length == 0)\n        {\n            throw new ArgumentException(SR.DataObject_EmptyFormatNotAllowed); \n        }\n\n        Name = name;\n        Id = id;\n    }\n\n    /// <summary>\n    ///  Specifies the name of this format.\n    /// </summary>\n    public string Name { get; }\n\n    /// <summary>\n    ///  Specifies the Id number for this format.\n    /// </summary>\n    public int Id { get; }\n\n    static DataFormat IDataFormat<DataFormat>.Create(string name, int id) => new(name, id);\n}","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DataFormat.cs#L4-L40","documentation":"The DataFormat constructor rejects a null or empty name. An empty format name has no meaning in the clipboard/drag-drop format registry, so passing name.Length == 0 throws ArgumentException (SR.DataObject_EmptyFormatNotAllowed).","triggerScenarios":"Calling new DataFormat(\"\", someId) or new DataFormat(name, id) where name is the empty string.","commonSituations":"Building custom clipboard formats from parsed strings where the parsed token can be empty (e.g. split results); dynamic format names derived from user or registry input.","solutions":["Validate the format name is non-empty before constructing DataFormat","Throw or log a descriptive error at the input boundary","Use DataFormats.GetDataFormat with a registered format name instead of hand-constructing"],"exampleFix":"// before\nvar format = new DataFormat(customName, customId);\n// after\nif (!string.IsNullOrEmpty(customName))\n{\n    var format = new DataFormat(customName, customId);\n}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(name)) throw new ArgumentException(\"Format name must be non-empty\", nameof(name));","typeGuard":"static bool IsValidFormatName(string name) => !string.IsNullOrEmpty(name);","tryCatchPattern":"try\n{\n    var format = new DataFormat(name, id);\n}\ncatch (ArgumentException ex)\n{\n    // name was null or empty; surface a validation error\n}","preventionTips":["Validate format names at the input boundary","Never pass tokens from string.Split without empty checks","Prefer DataFormats.GetDataFormat for named formats"],"tags":["wpf","clipboard","argument-validation"],"backgroundTag":"empty-required-field","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}