AvaloniaUI/Avalonia · error · ArgumentException
Invalid application identifier
Error message
Invalid application identifier
What it means
CreateApplicationFormat builds a cross-app-recognizable DataFormat and validates the identifier via IsValidApplicationFormatIdentifier (must be non-empty and contain only valid chars). An invalid identifier is rejected with ArgumentException because the platform name must be parseable/distinguishable.
Source
Thrown at src/Avalonia.Base/Input/DataFormat.cs:161
/// <typeparam name="T">The data type. Can be any reference type.</typeparam>
/// <param name="identifier">
/// The format identifier. This value is only used for equality comparisons within the process
/// and is never passed to the underlying platform.
/// </param>
/// <returns>A new <see cref="DataFormat{T}"/>.</returns>
public static DataFormat<T> CreateInProcessFormat<T>(string identifier)
where T : class
{
ThrowHelper.ThrowIfNullOrEmpty(identifier);
return new(DataFormatKind.InProcess, identifier);
}
private static DataFormat<T> CreateApplicationFormat<T>(string identifier)
where T : class
{
if (!IsValidApplicationFormatIdentifier(identifier))
throw new ArgumentException("Invalid application identifier", nameof(identifier));
return new(DataFormatKind.Application, identifier);
}
/// <summary>
/// Creates a new format for the current platform that returns an array of <see cref="byte"/>.
/// </summary>
/// <param name="identifier">
/// The format identifier. This value is not validated and is passed AS IS to the underlying platform.
/// Most systems use mime types, but macOS requires Uniform Type Identifiers (UTI).
/// </param>
/// <returns>A new <see cref="DataFormat"/>.</returns>
public static DataFormat<byte[]> CreateBytesPlatformFormat(string identifier)
=> CreatePlatformFormat<byte[]>(identifier);
/// <summary>
/// Creates a new format for the current platform that returns a <see cref="string"/>.
/// </summary>View on GitHub (pinned to 11c5427268)
Solutions
- Use a simple identifier of alphanumerics/allowed chars only (typically letters, digits, underscores, dots, hyphens).
- Sanitize input before creating the format.
- Validate non-empty first (CreateInProcessFormat already calls ThrowIfNullOrEmpty; for application formats, ensure a clean identifier).
Example fix
// before:
var f = DataFormat.CreateStringApplicationFormat(""); // throws
// or with bad chars:
var f = DataFormat.CreateStringApplicationFormat("my format!"); // throws
// after:
var f = DataFormat.CreateStringApplicationFormat("my-format"); Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrEmpty(identifier) && identifier.All(IsValidChar))
DataFormat.CreateStringApplicationFormat(identifier); Type guard
static bool IsValidApplicationId(string s) => !string.IsNullOrEmpty(s) && s.All(IsValidChar); // mirror IsValidApplicationFormatIdentifier
Prevention
- Use alphanumerics and simple separators (.-_) in identifiers.
- Sanitize user-derived identifiers before creating formats.
- Reject empty identifiers upstream.
When it happens
Trigger: Calling DataFormat.CreateStringApplicationFormat / CreateBytesApplicationFormat (which route to CreateApplicationFormat) with an empty string or a string containing characters failing IsValidChar (e.g. whitespace, punctuation, or control chars).
Common situations: Generating format identifiers from user input or app metadata that includes disallowed characters. Passing null/empty from a config default.
Related errors
- {nameof(KeySpline)} must have X coordinates >= 0.0 and <= 1.
- Invalid KeySpline X1 value. Must be >= 0.0 and <= 1.0.
- Invalid KeySpline X2 value. Must be >= 0.0 and <= 1.0.
- Cannot get system name for {Kind} format {Identifier}
- Size should be >= (1,1)
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/0018b6380daf5ac8.
Report an issue: GitHub.