dotnet/wpf · error · ArgumentOutOfRangeException
ArgumentException.PositiveValue (Parameter 'value')
Error message
ArgumentException.PositiveValue (Parameter 'value')
What it means
PageResolutionSetting's ResolutionX setter requires a strictly positive resolution; assigning 0 or a negative DPI value throws ArgumentOutOfRangeException with the resource message ArgumentException.PositiveValue. ResolutionX is stored in the ticket under the PageResolutionkeys.ResolutionX property.
Solutions
- Ensure the X resolution is > 0 before assigning.
- Only use PageResolution values reported by queue.GetPrintCapabilities().PageResolutions.
- Guard with a check or Math.Max(1, x) before assignment.
- Catch ArgumentOutOfRangeException and fall back to the queue's default resolution.
Example fix
// before resolution.X = dpiX; // may be 0 // after if (dpiX > 0) resolution.X = dpiX; else resolution = queue.DefaultPrintTicket.PageResolution;
Defensive patterns
Strategy: validation
Validate before calling
if (dpiX > 0)
resolution.X = dpiX; Type guard
bool IsValidResolutionX(object v) => v is int i && i > 0;
Try / catch
try { resolution.X = dpiX; }
catch (ArgumentOutOfRangeException) { resolution = queue.DefaultPrintTicket.PageResolution; } Prevention
- Take resolutions from queue.GetPrintCapabilities().PageResolutions
- Check config-loaded DPI values for zero before applying
- Treat 0/unloaded DPI as 'not set' instead of assigning it
When it happens
Trigger: Setting PageResolution.X (e.g. via a custom PageResolution on PrintTicket) to 0 or a negative number.
Common situations: Reading DPI from config that defaults to 0; computing resolution from device values that failed to load; copy/paste errors swapping width/height/zero placeholders.
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
- ArgumentException.NonNegativeValue (Parameter 'squareScale')
- ArgumentException.PositiveValue (Parameter 'value')
- PTUtility.GetTextFromResource("ArgumentException.PositiveVal…
- PTUtility.GetTextFromResource("ArgumentException.PositiveVal…
- Specified argument was out of range of valid values…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/90b6bf6bcd4a891f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageResolution.cs:348
/// Gets or sets the page resolution setting's X component.
/// </summary>
/// <remarks>
/// If this component is not specified yet, getter will return <see cref="PrintSchema.UnspecifiedIntValue"/>.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">
/// The value to set is not a positive integer.
/// </exception>
public int ResolutionX
{
get
{
return this[PrintSchemaTags.Keywords.PageResolutionKeys.ResolutionX];
}
set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException(nameof(value),
PTUtility.GetTextFromResource("ArgumentException.PositiveValue"));
}
this[PrintSchemaTags.Keywords.PageResolutionKeys.ResolutionX] = value;
}
}
/// <summary>
/// Gets or sets the page resolution setting's Y component.
/// </summary>
/// <remarks>
/// If this component is not specified yet, getter will return <see cref="PrintSchema.UnspecifiedIntValue"/>.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">
/// The value to set is not a positive integer.
/// </exception>
public int ResolutionY
{View on GitHub (pinned to 81131a70a4)