dotnet/wpf · error · ArgumentOutOfRangeException
PTUtility.GetTextFromResource("ArgumentException.PositiveVal…
Error message
PTUtility.GetTextFromResource("ArgumentException.PositiveValue") What it means
DocumentNUp.NUpSetting's PagesPerSheet setter validates the value and throws ArgumentOutOfRangeException with the 'ArgumentException.PositiveValue' resource when value <= 0. Pages-per-sheet must be a positive integer.
Solutions
- Only assign positive values: clamp or validate the input before setting NUpSetting.
- Fix the source (config file, UI input) that supplies 0 or negative values.
- Guard with an if/Max check before the assignment.
Example fix
// before
docNUp.NUpSetting = pagesPerSheet; // pagesPerSheet may be 0
// after
if (pagesPerSheet > 0)
{
docNUp.NUpSetting = pagesPerSheet;
} Defensive patterns
Strategy: validation
Validate before calling
if (pagesPerSheet <= 0) throw new ArgumentOutOfRangeException(nameof(pagesPerSheet));
Type guard
bool IsValidPagesPerSheet(int v) => v > 0;
Try / catch
catch (ArgumentOutOfRangeException) { /* clamp to 1 or reject input */ } Prevention
- Validate integer settings parsed from config/UI before applying them to PrintTicket.
- Use > 0 checks for all counts/quantities in print configuration.
When it happens
Trigger: Assigning 0 or a negative number to the NUpSetting/PagesPerSheet property of a DocumentNUp print configuration, e.g. reading the value from user input or a config file that contains 0 or an unset (defaulted to 0) integer.
Common situations: Building a PrintTicket programmatically where the N-up count comes from uninitialized UI state or parsed settings; persisted print configuration files with a zero value.
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
- args
- args
- ArgumentOutOfRangeException(authenticationType)
- ArgumentOutOfRangeException
- ArgumentOutOfRangeException(nameof(characterHit))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/3624add8fce60f11.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/DocumentNUp.cs:518
/// Gets or sets the value of number of logical pages per physical sheet.
/// </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 PagesPerSheet
{
get
{
return this[PrintSchemaTags.Keywords.NUpKeys.PagesPerSheet];
}
set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException(nameof(value),
PTUtility.GetTextFromResource("ArgumentException.PositiveValue"));
}
this[PrintSchemaTags.Keywords.NUpKeys.PagesPerSheet] = value;
}
}
/// <summary>
/// Gets a <see cref="NUpPresentationDirectionSetting"/> object that specifies the document NUp presentation direction setting.
/// </summary>
public NUpPresentationDirectionSetting PresentationDirection
{
get
{
if (_presentationDirection == null)
{
_presentationDirection = new NUpPresentationDirectionSetting(this._ownerPrintTicket)
{View on GitHub (pinned to 81131a70a4)