dotnet/wpf · error · ArgumentOutOfRangeException
PTUtility.GetTextFromResource("ArgumentException.PositiveVal…
Error message
PTUtility.GetTextFromResource("ArgumentException.PositiveValue") What it means
The JobCopyCount (copies) setting only accepts positive integers; assigning zero or a negative value throws ArgumentOutOfRangeException with a resource-loaded message. Copies count is meaningless at 0 or below, so the setter rejects it eagerly.
Solutions
- Ensure the value is >= 1 before assigning CopyCount.
- Clamp: Math.Max(1, computedCopies).
- Validate user input at the UI layer to require a positive integer.
- Wrap assignment in try/catch on ArgumentOutOfRangeException and fall back to 1 copy.
Example fix
// before printTicket.CopyCount = userCopies; // may be 0 // after printTicket.CopyCount = Math.Max(1, userCopies);
Defensive patterns
Strategy: validation
Validate before calling
if (copies is int c && c >= 1)
printTicket.CopyCount = c; Type guard
bool IsValidCopyCount(object v) => v is int i && i >= 1;
Try / catch
try { printTicket.CopyCount = copies; }
catch (ArgumentOutOfRangeException) { printTicket.CopyCount = 1; } Prevention
- Clamp user-supplied copy counts with Math.Max(1, n)
- Validate copy-count UI inputs as positive integers
- Never use loop counters that may reach 0 as copy counts
When it happens
Trigger: Setting PrintTicket.CopyCount (JobCopyCountSetting.Value) to 0 or a negative number.
Common situations: Computing copy count from user input or a loop counter that starts at 0; subtracting copies (count--) before printing; config values defaulting to 0.
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')
- ArgumentException.PositiveValue (Parameter 'value')
- 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/7f35485e43c22c61.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageCopyCount.cs:85
/// Gets or sets the value of job copy count.
/// </summary>
/// <remarks>
/// If this setting 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 Value
{
get
{
return this.IntValue;
}
set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException(nameof(value),
PTUtility.GetTextFromResource("ArgumentException.PositiveValue"));
}
this.IntValue = value;
}
}
#endregion Public Properties
#region Public Methods
/// <summary>
/// Converts the job copy count setting to human-readable string.
/// </summary>
/// <returns>A string that represents this job copy count setting.</returns>
public override string ToString()
{
return Value.ToString(CultureInfo.CurrentCulture);View on GitHub (pinned to 81131a70a4)