{"record":{"id":"2ab08b1c159a796a","repo":"dotnet/wpf","slug":"specified-argument-was-out-of-range-of-valid-values","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/PageMediaType.cs","lineNumber":255,"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=\"PageMediaType\"/>.\n        /// </exception>\n        public PageMediaType Value\n        {\n            get\n            {\n                return (PageMediaType)this[PrintSchemaTags.Framework.OptionNameProperty];\n            }\n            set\n            {\n                if (value < PrintSchema.PageMediaTypeEnumMin ||\n                    value > PrintSchema.PageMediaTypeEnumMax)\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 media type setting to human-readable string.\n        /// </summary>\n        /// <returns>A string that represents this page media type setting.</returns>\n        public override string ToString()\n        {\n            return Value.ToString();\n        }","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageMediaType.cs#L237-L273","documentation":"PageMediaTypeSetting.Value accepts only values within PrintSchema.PageMediaTypeEnumMin..Max; assigning an out-of-range integer (cast to the PageMediaType enum) throws a bare ArgumentOutOfRangeException for 'value'. The setter stores the value as the OptionName property of the print config element.","triggerScenarios":"Setting PageMediaType on a PrintTicket to a value outside the defined Print Schema enum range (e.g. an undefined enum member or an invalid int cast).","commonSituations":"Casting raw ints from config files or device settings into PageMediaType; enum values from older/newer framework versions not present in the schema range; parsing user input without validating the enum.","solutions":["Only assign valid PageMediaType enum members (use Enum.IsDefined before casting).","Clamp or map unknown values to a valid default (e.g. PageMediaType.None).","Validate ints read from config/DB against PrintSchema.PageMediaTypeEnumMin/Max before assignment.","Catch ArgumentOutOfRangeException and fall back to the queue default media type."],"exampleFix":"// before\nprintTicket.PageMediaType = (PageMediaType)rawInt; // may be undefined\n// after\nif (Enum.IsDefined(typeof(PageMediaType), rawInt))\n    printTicket.PageMediaType = (PageMediaType)rawInt;","handlingStrategy":"validation","validationCode":"if (Enum.IsDefined(typeof(PageMediaType), rawValue))\n    printTicket.PageMediaType = (PageMediaType)rawValue;","typeGuard":"bool IsValidPageMediaType(object v) => v is int i && i >= PrintSchema.PageMediaTypeEnumMin && i <= PrintSchema.PageMediaTypeEnumMax;","tryCatchPattern":"try { printTicket.PageMediaType = value; }\ncatch (ArgumentOutOfRangeException) { printTicket.PageMediaType = PageMediaType.None; }","preventionTips":["Only assign named PageMediaType enum members, never raw ints from config","Use Enum.IsDefined before any enum cast","Persist enum names (not numeric values) in configuration files"],"tags":["wpf","printing","argumentoutofrange","enum"],"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"}