{"record":{"id":"ed7b01557995e751","repo":"dotnet/wpf","slug":"specified-argument-was-out-of-range-of-valid-values-ed7b01","errorCode":null,"errorMessage":"Specified argument was out of range of valid values. (Parameter 'value')","messagePattern":"Specified argument was out of range of valid values\\. \\(Parameter 'value'\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PhotoPrintingIntent.cs","lineNumber":252,"sourceCode":"        /// </summary>\n        /// <remarks>\n        /// If the setting is not specified yet, getter will return 0.\n        /// </remarks>\n        /// <exception cref=\"ArgumentOutOfRangeException\">\n        /// The value to set is not one of the standard <see cref=\"PhotoPrintingIntent\"/>.\n        /// </exception>\n        public PhotoPrintingIntent Value\n        {\n            get\n            {\n                return (PhotoPrintingIntent)this[PrintSchemaTags.Framework.OptionNameProperty];\n            }\n            set\n            {\n                if (value < PrintSchema.PhotoPrintingIntentEnumMin ||\n                    value > PrintSchema.PhotoPrintingIntentEnumMax)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value));\n                }\n\n                this[PrintSchemaTags.Framework.OptionNameProperty] = (int)value;\n            }\n        }\n\n        #endregion Public Properties\n\n        #region Public Methods\n\n        /// <summary>\n        /// Converts the page photo printing intent setting to human-readable string.\n        /// </summary>\n        /// <returns>A string that represents this page photo printing intent setting.</returns>\n        public override string ToString()\n        {\n            return Value.ToString();\n        }","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PhotoPrintingIntent.cs#L234-L270","documentation":"The PagePhotoPrintingIntent setting setter validates the assigned value against PrintSchema.PhotoPrintingIntentEnumMin..Max. Values outside the PhotoPrintingIntent enum range throw ArgumentOutOfRangeException with parameter 'value'.","triggerScenarios":"Assigning printTicket.PagePhotoPrintingIntentPhotoPrintingIntent/Intent with an int outside the enum, commonly a cast from unvalidated external data.","commonSituations":"Restoring user settings saved under an older schema version; UI controls emitting raw integer indices that exceed the enum's max.","solutions":["Only assign defined PhotoPrintingIntent enum members (None, PhotoBest, PhotoDraft, unknown/unspecified)","Validate with Enum.IsDefined before casting","Catch ArgumentOutOfRangeException and reset to None"],"exampleFix":"// before\nintent = (PhotoPrintingIntent)comboBoxIndex;\nticket.PagePhotoPrintingIntent.Intent = intent;\n// after\nif (Enum.IsDefined(typeof(PhotoPrintingIntent), comboBoxIndex))\n    ticket.PagePhotoPrintingIntent.Intent = (PhotoPrintingIntent)comboBoxIndex;","handlingStrategy":"validation","validationCode":"bool IsValidPhotoPrintingIntent(int v) => v >= PrintSchema.PhotoPrintingIntentEnumMin && v <= PrintSchema.PhotoPrintingIntentEnumMax;","typeGuard":"static bool IsDefinedPhotoPrintingIntent(object v) => v is int i && i >= PrintSchema.PhotoPrintingIntentEnumMin && i <= PrintSchema.PhotoPrintingIntentEnumMax;","tryCatchPattern":"try { ticket.PagePhotoPrintingIntent.Intent = (PhotoPrintingIntent)value; }\ncatch (ArgumentOutOfRangeException) { ticket.PagePhotoPrintingIntent.Intent = PhotoPrintingIntent.None; }","preventionTips":["Use Enum.IsDefined before casting raw ints","Never store enum values as free-form ints","Reset to None/defaults on load failure"],"tags":["wpf","printing","enum","argumentoutofrange"],"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-22T01:17:13.364Z"}