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
PageTicket's PageResolution.QualitativeResolution setter validates that the assigned value lies within PrintSchema.PageQualitativeResolutionEnumMin..Max before storing it in the PrintTicket XML cache. Assigning any int outside the defined PageQualitativeResolution enum range throws ArgumentOutOfRangeException with parameter name 'value'.
Solutions
- Verify the value assigned to QualitativeResolution is a valid PrintQualitativeResolution enum member within PageQualitativeResolutionEnumMin..Max
- If loading from external data, validate or map the raw int to a known enum value before assignment
- Catch ArgumentOutOfRangeException and reset to a default resolution
Example fix
// before
res.QualitativeResolution = (int)userValue; // may be out of range
// after
if (userValue >= (int)PrintQualitativeResolution.ResolutionMin && userValue <= (int)PrintQualitativeResolution.ResolutionMax)
res.QualitativeResolution = userValue;
else
res.QualitativeResolution = PrintQualitativeResolution.Resolution300; Defensive patterns
Strategy: validation
Validate before calling
bool IsValidQualitativeResolution(int v) => v >= PrintSchema.PageQualitativeResolutionEnumMin && v <= PrintSchema.PageQualitativeResolutionEnumMax;
Type guard
static bool IsDefinedQualitativeResolution(object v) => v is int i && i >= PrintSchema.PageQualitativeResolutionEnumMin && i <= PrintSchema.PageQualitativeResolutionEnumMax;
Try / catch
try { ticket.PageResolution.QualitativeResolution = value; }
catch (ArgumentOutOfRangeException) { ticket.PageResolution.QualitativeResolution = PrintQualitativeResolution.Resolution300; } Prevention
- Always assign enum members, never raw ints
- Validate persisted values with Enum.IsDefined before casting
- Keep PrintTicket save/load schema versions aligned
When it happens
Trigger: Setting printTicket.PageResolution.QualitativeResolution to a raw int cast or computed value that is not one of the defined PrintQualitativeResolution enumeration values (or an out-of-range int from external data).
Common situations: Persisting a PrintTicket to XML and reloading it on a newer/older framework version where enum values changed; casting an unvalidated database or user-supplied int into the enum; deserializing settings from config files.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 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/2100c7302a04b52c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageResolution.cs:403
/// </summary>
/// <remarks>
/// If this quality label 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="PageQualitativeResolution"/>.
/// </exception>
public PageQualitativeResolution QualitativeResolution
{
get
{
return (PageQualitativeResolution)this[PrintSchemaTags.Keywords.PageResolutionKeys.QualitativeResolution];
}
set
{
if (value < PrintSchema.PageQualitativeResolutionEnumMin ||
value > PrintSchema.PageQualitativeResolutionEnumMax)
{
throw new ArgumentOutOfRangeException(nameof(value));
}
this[PrintSchemaTags.Keywords.PageResolutionKeys.QualitativeResolution] = (int)value;
}
}
#endregion Public Properties
#region Public Methods
/// <summary>
/// Converts the page resolution setting to human-readable string.
/// </summary>
/// <returns>A string that represents this page resolution setting.</returns>
public override string ToString()
{
return ResolutionX.ToString(CultureInfo.CurrentCulture) + "x" +
ResolutionY.ToString(CultureInfo.CurrentCulture) +View on GitHub (pinned to 81131a70a4)