{"record":{"id":"3630b4457841e0d9","repo":"dotnet/wpf","slug":"specified-argument-was-out-of-range-of-valid-values-3630b4","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/PageOrientation.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=\"PageOrientation\"/>.\n        /// </exception>\n        public PageOrientation Value\n        {\n            get\n            {\n                return (PageOrientation)this[PrintSchemaTags.Framework.OptionNameProperty];\n            }\n            set\n            {\n                if (value < PrintSchema.PageOrientationEnumMin ||\n                    value > PrintSchema.PageOrientationEnumMax)\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 orientation setting to human-readable string.\n        /// </summary>\n        /// <returns>A string that represents this page orientation 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/PageOrientation.cs#L234-L270","documentation":"PageOrientationSetting.Value accepts only values within PrintSchema.PageOrientationEnumMin..Max; assigning anything outside that range throws ArgumentOutOfRangeException('value'). The orientation is written to the ticket's OptionName property.","triggerScenarios":"Setting PrintTicket.PageOrientation to an out-of-range value (undefined enum member or invalid int cast).","commonSituations":"Casting ints from config or device-specific settings into PageOrientation; legacy code using removed enum values; parsing orientation strings with int.Parse without validation.","solutions":["Assign only valid PageOrientation enum members (Portrait, Landscape, ReversePortrait, ReverseLandscape).","Use Enum.IsDefined before casting raw ints.","Map unknown/unsupported orientations to PageOrientation.Portrait.","Catch ArgumentOutOfRangeException and use the queue's default orientation."],"exampleFix":"// before\nprintTicket.PageOrientation = (PageOrientation)userValue; // e.g. 99\n// after\nprintTicket.PageOrientation = Enum.IsDefined(typeof(PageOrientation), userValue)\n    ? (PageOrientation)userValue : PageOrientation.Portrait;","handlingStrategy":"validation","validationCode":"if (Enum.IsDefined(typeof(PageOrientation), rawValue))\n    printTicket.PageOrientation = (PageOrientation)rawValue;","typeGuard":"bool IsValidPageOrientation(object v) => v is int i && i >= PrintSchema.PageOrientationEnumMin && i <= PrintSchema.PageOrientationEnumMax;","tryCatchPattern":"try { printTicket.PageOrientation = value; }\ncatch (ArgumentOutOfRangeException) { printTicket.PageOrientation = PageOrientation.Portrait; }","preventionTips":["Map user-facing orientation strings to enum members explicitly","Use Enum.IsDefined before casting","Default to Portrait when the source value is unknown"],"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"}