dotnet/wpf · error · ArgumentException
SR.PrintDialogZeroNotAllowed
Error message
SR.PrintDialogZeroNotAllowed
What it means
PrintDialog.MinPage is a page-range bound used by the print dialog UI, and WPF requires both MinPage and MaxPage to be strictly positive. Setting MinPage to zero or a negative value throws ArgumentException(SR.PrintDialogZeroNotAllowed) to keep the printed page range valid (pages are 1-based).
Solutions
- Only assign MinPage values >= 1; clamp or reject non-positive input before setting the property.
- If the source is 0-based numbering, add 1 before assigning.
- Guard the assignment: if (candidate >= 1) dialog.MinPage = candidate;
Example fix
// before printDialog.MinPage = firstPage; // firstPage may be 0 // after printDialog.MinPage = Math.Max(1, firstPage);
Defensive patterns
Strategy: validation
Validate before calling
if (candidateMinPage < 1) throw new ArgumentOutOfRangeException(nameof(candidateMinPage)); printDialog.MinPage = candidateMinPage;
Type guard
bool IsValidPageBound(int v) => v >= 1;
Try / catch
try { printDialog.MinPage = value; }
catch (ArgumentException ex) { /* ex.Message mentions MinPage; fall back to default 1 */ printDialog.MinPage = 1; } Prevention
- Clamp all page-range inputs with Math.Max(1, value) before assignment.
- Never bind MinPage/MaxPage directly to 0-based or uninitialized ints.
- Validate persisted print settings on load, treating 0 as invalid.
When it happens
Trigger: Assigning a value <= 0 to PrintDialog.MinPage, e.g. printDialog.MinPage = 0 or initializing it from parsed config/CLI input where the value defaults to 0.
Common situations: Initializing MinPage from an int that defaults to 0 before parsing user input; copying bounds from another dialog that uses 0-based page numbering; deserializing settings where MinPage was saved as 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
- ArgumentOutOfRangeException (timeout was Duration.Automatic)
- Collection_BadRank
- Collection_CopyTo_ArrayCannotBeMultidimensional
- Collection_CopyTo_ArrayCannotBeMultidimensional
- Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/62ab761c3fc4784a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PrintDialog.cs:161
}
// the following two properties return non CLS-compliant type UInt32 (bug 1788246)
#pragma warning disable 3003
/// <summary>
/// Gets or sets the minimum page number allowed in the page ranges.
/// </summary>
public UInt32 MinPage
{
get
{
return _minPage;
}
set
{
if (_minPage <= 0)
{
throw new System.ArgumentException(SR.Format(SR.PrintDialogZeroNotAllowed, "MinPage"));
}
_minPage = value;
}
}
/// <summary>
/// Gets or sets the maximum page number allowed in the page ranges.
/// </summary>
public UInt32 MaxPage
{
get
{
return _maxPage;
}
set
{
if (_maxPage <= 0)View on GitHub (pinned to 81131a70a4)