AvaloniaUI/Avalonia · error · ArgumentException

Unrecognized cursor type '{s}'.

Error message

Unrecognized cursor type '{s}'.

What it means

Cursor.Parse converts a cursor name string into a Cursor by matching it against the StandardCursorType enum (case-insensitive). If the string is not a known standard cursor name, there is no valid cursor to build, so it throws ArgumentException.

Source

Thrown at src/Avalonia.Base/Input/Cursor.cs:71

        public Cursor(StandardCursorType cursorType)
            : this(GetCursorFactory().GetCursor(cursorType), cursorType.ToString())
        {
        }

        public Cursor(Bitmap cursor, PixelPoint hotSpot)
            : this(GetCursorFactory().CreateCursor(cursor, hotSpot), "BitmapCursor")
        {
        }

        internal ICursorImpl PlatformImpl { get; }

        public void Dispose() => PlatformImpl.Dispose();

        public static Cursor Parse(string s)
        {
            return Enum.TryParse<StandardCursorType>(s, true, out var t) ?
                new Cursor(t) :
                throw new ArgumentException($"Unrecognized cursor type '{s}'.");
        }

        private static ICursorFactory GetCursorFactory()
        {
            return AvaloniaLocator.Current.GetRequiredService<ICursorFactory>();
        }

        public override string ToString()
        {
            return _name;
        }
    }
}

View on GitHub (pinned to 11c5427268)

Solutions

  1. Use a value from the StandardCursorType enum (case-insensitive).
  2. Validate the string first with `Enum.TryParse<StandardCursorType>(s, true, out _)`.
  3. Fall back to a default cursor when the name is unrecognized instead of letting Parse throw.

Example fix

// before:
var c = Cursor.Parse(userInput); // throws on unknown

// after:
Cursor c = Enum.TryParse<StandardCursorType>(userInput, true, out var t)
    ? new Cursor(t)
    : Cursor.Default;
Defensive patterns

Strategy: validation

Validate before calling

Cursor c = Enum.TryParse<StandardCursorType>(s, true, out var t)
    ? new Cursor(t)
    : Cursor.Default;

Type guard

static bool IsKnownCursor(string s) => Enum.TryParse<StandardCursorType>(s, true, out _);

Try / catch

try { return Cursor.Parse(s); }
catch (ArgumentException) { return Cursor.Default; }

Prevention

When it happens

Trigger: Calling `Cursor.Parse("hand" /*typo*/)` or `Cursor.Parse("grab")` with a string that is not one of the StandardCursorType enum values (e.g. Arrow, Ibeam, Wait, Cross, Hand, AppStarting, Help, No, SizeAll, SizeNESW, SizeNS, SizeNWSE, SizeWE, UpArrow, None, ContextMenu, DragCopy, DragMove, DragLink, BottomSide, TopSide, LeftSide, RightSide, TopLeftCorner, TopRightCorner, BottomLeftCorner, BottomRightCorner).

Common situations: Parsing cursor names from config/XAML/JSON with a typo or using a CSS cursor name not present in StandardCursorType. Reading theme strings that contain unexpected values.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/554ce0f4feca2ce6. Report an issue: GitHub.