dotnet/wpf · error · ArgumentOutOfRangeException
Specified argument was out of the range of valid values…
Error message
Specified argument was out of the range of valid values. (Parameter 'value')
What it means
The PrintTicket.PageResolution setter validates the PageResolution object: if no QualitativeResolution label is given, both X and Y must be provided, otherwise ArgumentOutOfRangeException("value") is thrown. The Print Schema requires a resolution to be either qualitative (e.g. High) or quantitative (explicit X/Y DPI); a Resolution that is neither is meaningless.
Solutions
- Provide both X and Y (positive DPI values) when not using a qualitative label.
- Or set QualitativeResolution (e.g. PageQualitativeResolution.High) instead of/in addition to X and Y.
- Validate the constructed PageResolution for null members before assigning it to PageResolution.
Example fix
// before ticket.PageResolution = new PageResolution(600, null, null); // after ticket.PageResolution = new PageResolution(600, 600); // X and Y both supplied
Defensive patterns
Strategy: validation
Validate before calling
bool isValidResolution(PageResolution r) =>
r != null &&
(r.QualitativeResolution != null || (r.X != null && r.Y != null));
if (isValidResolution(candidate)) ticket.PageResolution = candidate; Type guard
bool IsCompleteResolution(PageResolution r) =>
r != null && (r.QualitativeResolution != null || (r.X != null && r.Y != null)); Try / catch
try { ticket.PageResolution = resolution; }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "value")
{ ticket.PageResolution = new PageResolution(600, 600); Log.Warn("Incomplete resolution replaced with default"); } Prevention
- Construct PageResolution via a factory that requires either X+Y or a qualitative label.
- Validate all three members for null-ness before assignment.
- When copying resolution objects, deep-copy all members together.
When it happens
Trigger: Assigning ticket.PageResolution = new PageResolution(null, null, null) or a PageResolution with QualitativeResolution == null and (X == null or Y == null), e.g. PageResolution(600, null).
Common situations: Constructing PageResolution from separate config fields where X or Y is missing; copying resolution objects between tickets and dropping one dimension; binding X and Y from UI where only one box is filled.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Value must be positive.
- Specified argument was out of range of valid values…
- SR.ParameterMustBeGreaterThanZero
- args
- args
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/f57b675fe6c1f232.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrtTicket_Public_Simple.cs:1029
else if ((int)_printTicket.PageResolution.QualitativeResolution != PrintSchema.EnumUnspecifiedValue)
{
// No valid x/y values but we do have valid quality label value.
return new PageResolution(_printTicket.PageResolution.QualitativeResolution);
}
else
{
return null;
}
}
set
{
// first performing input parameter validation
if (value != null)
{
if ((value.QualitativeResolution == null) &&
(value.X == null || value.Y == null))
{
throw new ArgumentOutOfRangeException(nameof(value));
}
// If quality lable is specified, it needs to be valid value
if ((value.QualitativeResolution != null) &&
(value.QualitativeResolution < PrintSchema.PageQualitativeResolutionEnumMin ||
value.QualitativeResolution > PrintSchema.PageQualitativeResolutionEnumMax))
{
throw new ArgumentOutOfRangeException(nameof(value));
}
// If specified, resolution X and Y values must be positive
if ((value.X != null) && (value.X <= 0))
{
throw new ArgumentOutOfRangeException(nameof(value),
PTUtility.GetTextFromResource("ArgumentException.PositiveValue"));
}
if ((value.Y != null) && (value.Y <= 0))View on GitHub (pinned to 81131a70a4)