{"record":{"id":"5b5da3e0b6c94dcc","repo":"dotnet/wpf","slug":"specified-argument-was-out-of-range-of-valid-values-prtcap","errorCode":null,"errorMessage":"Specified argument was out of range of valid values. (Parameter 'feature')","messagePattern":"Specified argument was out of range of valid values\\. \\(Parameter 'feature'\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrtCap_Public.cs","lineNumber":110,"sourceCode":"        #endregion Constructors\n\n        #region Public Methods\n\n        /// <summary>\n        /// Gets a Boolean value indicating whether the device supports a specific capability.\n        /// </summary>\n        /// <param name=\"feature\">Capability feature to check for device support.</param>\n        /// <returns>True if the capability is supported. False otherwise.</returns>\n        /// <exception cref=\"ArgumentOutOfRangeException\">\n        /// The <paramref name=\"feature\"/> parameter is not a standard feature defined in <see cref=\"CapabilityName\"/>.\n        /// </exception>\n        public bool SupportsCapability(CapabilityName feature)\n        {\n            // Verify input parameter\n            if (feature < PrintSchema.CapabilityNameEnumMin ||\n                feature > PrintSchema.CapabilityNameEnumMax)\n            {\n                throw new ArgumentOutOfRangeException(nameof(feature));\n            }\n\n            return (_pcRootFeatures[(int)feature] != null);\n        }\n\n        #endregion Public Methods\n\n        #region Public Properties\n\n        /// <summary>\n        /// Gets a <see cref=\"DocumentCollateCapability\"/> object that specifies the device's document collate capability.\n        /// </summary>\n        /// <remarks>\n        /// If the device doesn't support this capability, null reference will be returned.\n        /// You should use <see cref=\"SupportsCapability\"/> to check the capability is supported before accessing the returned reference.\n        /// </remarks>\n        public DocumentCollateCapability DocumentCollateCapability\n        {","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrtCap_Public.cs#L92-L128","documentation":"PrintCapabilities.SupportsCapability validates the CapabilityName parameter against PrintSchema.CapabilityNameEnumMin..Max before indexing the internal feature table. Passing a value outside the defined CapabilityName enum range throws ArgumentOutOfRangeException with parameter 'feature'.","triggerScenarios":"Calling printCapabilities.SupportsCapability((CapabilityName)someInt) where someInt is not a defined CapabilityName member, often from data-driven code that iterates raw ints.","commonSituations":"Looping capability checks with an upper bound larger than the enum; persisted capability lists from an older framework version containing removed values.","solutions":["Pass only defined CapabilityName enum members","Validate raw ints with Enum.IsDefined before casting to CapabilityName","Catch ArgumentOutOfRangeException when enumerating unknown capabilities"],"exampleFix":"// before\nfor (int i = 0; i < count; i++)\n    caps.SupportsCapability((CapabilityName)i);\n// after\nif (Enum.IsDefined(typeof(CapabilityName), i))\n    caps.SupportsCapability((CapabilityName)i);","handlingStrategy":"type-guard","validationCode":"bool IsValidCapabilityName(CapabilityName f) => f >= PrintSchema.CapabilityNameEnumMin && f <= PrintSchema.CapabilityNameEnumMax;","typeGuard":"static bool IsDefinedCapability(object v) => v is CapabilityName c && c >= PrintSchema.CapabilityNameEnumMin && c <= PrintSchema.CapabilityNameEnumMax;","tryCatchPattern":"try { supports = caps.SupportsCapability(feature); }\ncatch (ArgumentOutOfRangeException) { supports = false; }","preventionTips":["Iterate CapabilityName values via Enum.GetValues, not int ranges","Validate ints from external sources with Enum.IsDefined","Re-check capability lists when upgrading framework versions"],"tags":["wpf","printing","enum","argumentoutofrange"],"backgroundTag":"invalid-enum-argument","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"}