dotnet/wpf · error · ArgumentException
SR.InvalidCursorType (cursorType)
Error message
SR.InvalidCursorType (cursorType)
What it means
The Cursor(CursorType) constructor checks IsValidCursorType and throws ArgumentException (SR.InvalidCursorType) when the CursorType value is not a valid Win32-supported cursor type. Only a subset of CursorType members are loadable as system cursors.
Solutions
- Use Cursors.AppStarting/Cursors.Wait etc. predefined static cursors instead of constructing from CursorType.
- Only construct with CursorType members known valid (Arrow, Wait, Cross, Hand, IBeam, SizeAll, etc.).
- Validate with Enum.IsDefined and a whitelist of supported types before constructing.
Example fix
// before this.Cursor = new Cursor((CursorType)storedValue); // after this.Cursor = Cursors.Wait; // or validate storedValue against a whitelist first
Defensive patterns
Strategy: validation
Validate before calling
var valid = new HashSet<CursorType>{ CursorType.Arrow, CursorType.Wait, CursorType.Cross, CursorType.Hand, CursorType.IBeam, CursorType.SizeAll };
if (valid.Contains(type)) this.Cursor = new Cursor(type); Type guard
static bool IsValidCursorTypeValue(CursorType c) => Enum.IsDefined(typeof(CursorType), c);
Try / catch
try { this.Cursor = new Cursor(type); } catch (ArgumentException ex) { this.Cursor = Cursors.Arrow; } Prevention
- Prefer the predefined Cursors.* static instances
- Whitelist CursorType values instead of enumerating all members
- Persist cursor choices as names and validate on load
When it happens
Trigger: new Cursor((CursorType)outOfRangeInt) or new Cursor(CursorType member not supported by LoadCursorHelper, e.g. values outside the standard system cursor set).
Common situations: Restoring cursor selection from an int saved in settings, or iterating CursorType enum values assuming all are valid constructor inputs.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- ArgumentOutOfRangeException (timeout was Duration.Automatic)
- Collection_BadRank
- Collection_CopyTo_ArrayCannotBeMultidimensional
- Collection_CopyTo_ArrayCannotBeMultidimensional
- Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/0d486d5c5a84ce2d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs:32
/// </summary>
[TypeConverter(typeof(CursorConverter))]
[Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)]
public sealed class Cursor : IDisposable
{
/// <summary>
/// Constructor for Standard Cursors, needn't be public as Stock Cursors
/// are exposed in Cursors clas.
/// </summary>
/// <param name="cursorType"></param>
internal Cursor(CursorType cursorType)
{
if (IsValidCursorType(cursorType))
{
LoadCursorHelper(cursorType);
}
else
{
throw new ArgumentException(SR.Format(SR.InvalidCursorType, cursorType));
}
}
/// <summary>
/// Cursor from .ani or .cur file
/// </summary>
/// <param name="cursorFile"></param>
public Cursor(string cursorFile):this(cursorFile, false)
{
}
/// <summary>
/// Cursor from .ani or .cur file
/// </summary>
/// <param name="cursorFile"></param>
/// <param name="scaleWithDpi"></param>
public Cursor(string cursorFile, bool scaleWithDpi)
{View on GitHub (pinned to 81131a70a4)