dotnet/wpf · error · ArgumentOutOfRangeException
Specified argument was out of range of valid values…
Error message
Specified argument was out of range of valid values. (Parameter 'value')
What it means
PageOutputQualitySetting.Value accepts only values within PrintSchema.OutputQualityEnumMin..Max; out-of-range assignments throw ArgumentOutOfRangeException('value'). Quality (draft/normal/high/etc.) is stored as the OptionName property.
Solutions
- Assign only valid OutputQuality enum members (Unknown, Draft, Low, Normal, High, Photographic, etc.).
- Validate with Enum.IsDefined before casting raw values.
- Default unknown quality values to OutputQuality.Normal.
- Catch ArgumentOutOfRangeException and use the queue's default quality.
Example fix
// before
printTicket.OutputQuality = (OutputQuality)qualityInt;
// after
printTicket.OutputQuality = Enum.IsDefined(typeof(OutputQuality), qualityInt)
? (OutputQuality)qualityInt : OutputQuality.Normal; Defensive patterns
Strategy: validation
Validate before calling
if (Enum.IsDefined(typeof(OutputQuality), rawValue))
printTicket.OutputQuality = (OutputQuality)rawValue; Type guard
bool IsValidOutputQuality(object v) => v is int i && i >= PrintSchema.OutputQualityEnumMin && i <= PrintSchema.OutputQualityEnumMax;
Try / catch
try { printTicket.OutputQuality = value; }
catch (ArgumentOutOfRangeException) { printTicket.OutputQuality = OutputQuality.Normal; } Prevention
- Use named OutputQuality members only
- Validate quality values read from preferences files
- Default to Normal for unrecognized quality levels
When it happens
Trigger: Setting PrintTicket.OutputQuality to a value outside the OutputQuality enum's schema range (undefined member or invalid int cast).
Common situations: Casting quality ints from user preferences or app settings; enum values from custom quality levels not in the Print Schema; round-tripping tickets between framework versions.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Specified argument was out of range of valid values…
- Specified argument was out of range of valid values…
- Specified argument was out of range of valid values…
- Specified argument was out of range of valid values…
- Specified argument was out of range of valid values…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/5aae9a6603e09fb4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageOutputQuality.cs:254
/// </summary>
/// <remarks>
/// If the setting is not specified yet, getter will return 0.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">
/// The value to set is not one of the standard <see cref="OutputQuality"/>.
/// </exception>
public OutputQuality Value
{
get
{
return (OutputQuality)this[PrintSchemaTags.Framework.OptionNameProperty];
}
set
{
if (value < PrintSchema.OutputQualityEnumMin ||
value > PrintSchema.OutputQualityEnumMax)
{
throw new ArgumentOutOfRangeException(nameof(value));
}
this[PrintSchemaTags.Framework.OptionNameProperty] = (int)value;
}
}
#endregion Public Properties
#region Public Methods
/// <summary>
/// Converts the page output quality setting to human-readable string.
/// </summary>
/// <returns>A string that represents this page output quality setting.</returns>
public override string ToString()
{
return Value.ToString();
}View on GitHub (pinned to 81131a70a4)