AvaloniaUI/Avalonia · error · InvalidOperationException
Cannot get system name for {Kind} format {Identifier}
Error message
Cannot get system name for {Kind} format {Identifier} What it means
ToSystemName produces the platform-facing string for a DataFormat. Only Application (prefix + identifier) and Platform (raw identifier) kinds have a meaningful system name; Universal and InProcess formats do not map to a platform string, so the method throws InvalidOperationException for them.
Source
Thrown at src/Avalonia.Base/Input/DataFormat.cs:65
/// <summary>
/// Creates a name for this format, usable by the underlying platform.
/// </summary>
/// <param name="applicationPrefix">The system prefix used to recognize the name as an application format.</param>
/// <returns>A system name for the format.</returns>
/// <remarks>
/// This method can only be called if <see cref="Kind"/> is
/// <see cref="DataFormatKind.Application"/> or <see cref="DataFormatKind.Platform"/>.
/// </remarks>
public string ToSystemName(string applicationPrefix)
{
ThrowHelper.ThrowIfNull(applicationPrefix);
return Kind switch
{
DataFormatKind.Application => applicationPrefix + Identifier,
DataFormatKind.Platform => Identifier,
_ => throw new InvalidOperationException($"Cannot get system name for {Kind} format {Identifier}")
};
}
/// <inheritdoc />
public bool Equals(DataFormat? other)
{
if (other is null)
return false;
if (ReferenceEquals(this, other))
return true;
return Kind == other.Kind && Identifier == other.Identifier;
}
/// <inheritdoc />
public override bool Equals(object? obj)
=> Equals(obj as DataFormat);
/// <inheritdoc />View on GitHub (pinned to 11c5427268)
Solutions
- Only call ToSystemName on Application or Platform formats.
- For Universal formats, use the platform's built-in text/file/bitmap handling rather than a custom system name.
- Guard on Kind before calling: `if (format.Kind is Application or Platform) ...`.
Example fix
// before:
var name = DataFormat.Text.ToSystemName("myapp:"); // Universal -> throws
// after:
string name = format.Kind switch
{
DataFormatKind.Application => format.ToSystemName("myapp:"),
DataFormatKind.Platform => format.ToSystemName("myapp:"),
_ => throw new InvalidOperationException($"No system name for {format.Kind}")
}; Defensive patterns
Strategy: validation
Validate before calling
if (format.Kind is not (DataFormatKind.Application or DataFormatKind.Platform))
throw new InvalidOperationException($"No system name for {format.Kind}.");
var name = format.ToSystemName(prefix); Type guard
static bool HasSystemName(DataFormat f) => f.Kind is DataFormatKind.Application or DataFormatKind.Platform;
Prevention
- Only call ToSystemName on Application/Platform formats.
- Handle Universal formats (Text/Bitmap/File) via platform built-ins.
- Branch on Kind before producing system names.
When it happens
Trigger: Calling `format.ToSystemName(prefix)` on a DataFormat whose Kind is Universal (e.g. DataFormat.Text/Bitmap/File) or InProcess (created via CreateInProcessFormat<T>).
Common situations: Passing the built-in DataFormat.Text/DataFormat.File to a clipboard/drag-drop routine that calls ToSystemName. Trying to get a system name for an in-process-only format.
Related errors
- Invalid application identifier
- Cannot determine visual parent.
- BindingExpression has not been started.
- Cannot call AsObservable on a to binding expression which is
- BindingExpression was already attached.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/6088482a5f2e2b27.
Report an issue: GitHub.