{"record":{"id":"5c281db1c290a847","repo":"dotnet/wpf","slug":"specified-argument-was-out-of-range-of-valid-values-5c281d","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/PageTrueTypeFont.cs","lineNumber":254,"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=\"TrueTypeFontMode\"/>.\n        /// </exception>\n        public TrueTypeFontMode Value\n        {\n            get\n            {\n                return (TrueTypeFontMode)this[PrintSchemaTags.Framework.OptionNameProperty];\n            }\n            set\n            {\n                if (value < PrintSchema.TrueTypeFontModeEnumMin ||\n                    value > PrintSchema.TrueTypeFontModeEnumMax)\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 TrueType font handling mode setting to human-readable string.\n        /// </summary>\n        /// <returns>A string that represents this page TrueType font handling mode setting.</returns>\n        public override string ToString()\n        {\n            return Value.ToString();\n        }","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageTrueTypeFont.cs#L236-L272","documentation":"The PageTrueTypeFont mode setting setter validates the assigned value against PrintSchema.TrueTypeFontModeEnumMin..Max. Assigning an int outside the defined TrueTypeFontMode enum range throws ArgumentOutOfRangeException with parameter 'value'.","triggerScenarios":"Assigning printTicket.PageTrueTypeFont.Mode (or the underlying PageTrueTypeFontModeSetting.Value) with a raw int not in the TrueTypeFontMode enum, e.g. from persisted data or an unvalidated cast.","commonSituations":"Loading saved PrintTicket XML from a different runtime version; round-tripping enum values through string/int config stores.","solutions":["Ensure the assigned value is a valid TrueTypeFontMode enum member","Validate raw ints from external sources against Enum.IsDefined before casting","Catch ArgumentOutOfRangeException and fall back to DeviceFont or Automatic default"],"exampleFix":"// before\nmode = (TrueTypeFontMode)rawInt;\nticket.PageTrueTypeFont.Mode = mode;\n// after\nif (Enum.IsDefined(typeof(TrueTypeFontMode), rawInt))\n    ticket.PageTrueTypeFont.Mode = (TrueTypeFontMode)rawInt;","handlingStrategy":"validation","validationCode":"bool IsValidTrueTypeFontMode(int v) => v >= PrintSchema.TrueTypeFontModeEnumMin && v <= PrintSchema.TrueTypeFontModeEnumMax;","typeGuard":"static bool IsDefinedTrueTypeFontMode(object v) => v is int i && i >= PrintSchema.TrueTypeFontModeEnumMin && i <= PrintSchema.TrueTypeFontModeEnumMax;","tryCatchPattern":"try { ticket.PageTrueTypeFont.Mode = (TrueTypeFontMode)value; }\ncatch (ArgumentOutOfRangeException) { ticket.PageTrueTypeFont.Mode = TrueTypeFontMode.Automatic; }","preventionTips":["Bind UI to enum values, not raw ints","Validate values read from config/data stores","Guard against schema drift between framework versions"],"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"}