dotnet/wpf · error · ArgumentException
SR.DataObject_EmptyFormatNotAllowed
Error message
SR.DataObject_EmptyFormatNotAllowed
What it means
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).
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
Example fix
// before
var format = new DataFormat(customName, customId);
// after
if (!string.IsNullOrEmpty(customName))
{
var format = new DataFormat(customName, customId);
} Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(name)) throw new ArgumentException("Format name must be non-empty", nameof(name)); Type guard
static bool IsValidFormatName(string name) => !string.IsNullOrEmpty(name);
Try / catch
try
{
var format = new DataFormat(name, id);
}
catch (ArgumentException ex)
{
// name was null or empty; surface a validation error
} Prevention
- Validate format names at the input boundary
- Never pass tokens from string.Split without empty checks
- Prefer DataFormats.GetDataFormat for named formats
When it happens
Trigger: Calling new DataFormat("", someId) or new DataFormat(name, id) where name is the empty string.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- InvalidEnumArgumentException(nameof(format), (int)format…
- SR.DataObject_EmptyFormatNotAllowed
- ' ' is not a valid value for ' '.
- ArgumentException(message, name)
- ArgumentNullException(name)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/8e0c7a723f9ed1a3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DataFormat.cs:22
using System.Private.Windows.Ole;
namespace System.Windows;
/// <summary>
/// Represents a data format type.
/// </summary>
public sealed class DataFormat : IDataFormat<DataFormat>
{
/// <summary>
/// Initializes a new instance of the DataFormat class and specifies format name and id.
/// </summary>
public DataFormat(string name, int id)
{
ArgumentNullException.ThrowIfNull(name);
if (name.Length == 0)
{
throw new ArgumentException(SR.DataObject_EmptyFormatNotAllowed);
}
Name = name;
Id = id;
}
/// <summary>
/// Specifies the name of this format.
/// </summary>
public string Name { get; }
/// <summary>
/// Specifies the Id number for this format.
/// </summary>
public int Id { get; }
static DataFormat IDataFormat<DataFormat>.Create(string name, int id) => new(name, id);
}View on GitHub (pinned to 81131a70a4)