dotnet/wpf · error · ArgumentOutOfRangeException

ArgumentException.PositiveValue (Parameter 'value')

Error message

ArgumentException.PositiveValue (Parameter 'value')

What it means

PrintTicket.CopyCount requires a strictly positive integer (>= 1). Assigning zero or a negative value throws ArgumentOutOfRangeException with the resource message ArgumentException.PositiveValue. Zero is handled as 'clear the setting' in other paths, but a negative value always throws.

Solutions

  1. Clamp CopyCount to >= 1 before assignment; use null to reset to unspecified
  2. Validate the copies input control to disallow values below 1
  3. Catch ArgumentOutOfRangeException and show a validation message

Example fix

// before
ticket.CopyCount = userCopies; // could be 0 or negative
// after
ticket.CopyCount = userCopies > 0 ? userCopies : (int?)null;
Defensive patterns

Strategy: validation

Validate before calling

if (copies.HasValue && copies.Value <= 0) throw new ArgumentException("CopyCount must be positive", nameof(copies));

Type guard

static bool IsValidCopyCount(int? v) => v == null || v > 0;

Try / catch

try { ticket.CopyCount = copies; }
catch (ArgumentOutOfRangeException) { ShowValidationError("Copies must be at least 1"); }

Prevention

When it happens

Trigger: Setting printTicket.CopyCount to 0 or a negative number, e.g. from a spin editor that allows 0 or from unvalidated computed values.

Common situations: Print dialogs where the copies field is cleared to empty/0 before submission; subtraction producing negative counts.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/48900f6ee6e63097. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrtTicket_Public_Simple.cs:403

            {
                int copyValue = _printTicket.JobCopyCount.Value;

                if (copyValue > 0)
                    return copyValue;
                else
                    return null;
            }
            set
            {
                if (value == null)
                {
                    _printTicket.JobCopyCount.ClearSetting();
                }
                else
                {
                    if (value <= 0)
                    {
                        throw new ArgumentOutOfRangeException(nameof(value),
                                      PTUtility.GetTextFromResource("ArgumentException.PositiveValue"));
                    }

                    // no need to cache set calls
                    _printTicket.JobCopyCount.Value = (int)value;
                }

                // Raise PropertyChanged event for IPropertyChange implementation
                NotifyPropertyChanged("CopyCount");
            }
        }

        /// <summary>
        /// Gets or sets the device font substitution setting.
        /// </summary>
        /// <remarks>
        /// If the device font substitution setting is not specified, this property will return null.
        /// If caller sets this property to null, device font substitution setting will become unspecified and

View on GitHub (pinned to 81131a70a4)