{"record":{"id":"0d486d5c5a84ce2d","repo":"dotnet/wpf","slug":"sr-invalidcursortype-cursortype","errorCode":null,"errorMessage":"SR.InvalidCursorType (cursorType)","messagePattern":"SR\\.InvalidCursorType \\(cursorType\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs","lineNumber":32,"sourceCode":"    /// </summary>\n    [TypeConverter(typeof(CursorConverter))]\n    [Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)]\n    public sealed class Cursor : IDisposable\n    {\n        /// <summary>\n        /// Constructor for Standard Cursors, needn't be public as Stock Cursors\n        /// are exposed in Cursors clas.\n        /// </summary>\n        /// <param name=\"cursorType\"></param>\n        internal Cursor(CursorType cursorType)\n        {\n            if (IsValidCursorType(cursorType))\n            {\n                LoadCursorHelper(cursorType);\n            }\n            else\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidCursorType, cursorType));\n            }\n        }\n\n        /// <summary>\n        /// Cursor from .ani or .cur file\n        /// </summary>\n        /// <param name=\"cursorFile\"></param>\n        public Cursor(string cursorFile):this(cursorFile, false)\n        {\n        }\n\n        /// <summary>\n        /// Cursor from .ani or .cur file\n        /// </summary>\n        /// <param name=\"cursorFile\"></param>\n        /// <param name=\"scaleWithDpi\"></param>\n        public Cursor(string cursorFile, bool scaleWithDpi)\n        {","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs#L14-L50","documentation":"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.","triggerScenarios":"new Cursor((CursorType)outOfRangeInt) or new Cursor(CursorType member not supported by LoadCursorHelper, e.g. values outside the standard system cursor set).","commonSituations":"Restoring cursor selection from an int saved in settings, or iterating CursorType enum values assuming all are valid constructor inputs.","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."],"exampleFix":"// before\nthis.Cursor = new Cursor((CursorType)storedValue);\n// after\nthis.Cursor = Cursors.Wait; // or validate storedValue against a whitelist first","handlingStrategy":"validation","validationCode":"var valid = new HashSet<CursorType>{ CursorType.Arrow, CursorType.Wait, CursorType.Cross, CursorType.Hand, CursorType.IBeam, CursorType.SizeAll };\nif (valid.Contains(type)) this.Cursor = new Cursor(type);","typeGuard":"static bool IsValidCursorTypeValue(CursorType c) => Enum.IsDefined(typeof(CursorType), c);","tryCatchPattern":"try { this.Cursor = new Cursor(type); } catch (ArgumentException ex) { this.Cursor = Cursors.Arrow; }","preventionTips":["Prefer the predefined Cursors.* static instances","Whitelist CursorType values instead of enumerating all members","Persist cursor choices as names and validate on load"],"tags":["wpf","cursor","argument-exception"],"backgroundTag":"invalid-enum-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}