dotnet/wpf · error · ArgumentOutOfRangeException
ArgumentException.NonNegativeValue (Parameter 'squareScale')
Error message
ArgumentException.NonNegativeValue (Parameter 'squareScale')
What it means
PrintTicket.PageScaling.SetCustomSquareScaling requires a non-negative square scaling percentage. A negative squareScale argument throws ArgumentOutOfRangeException with the resource message ArgumentException.NonNegativeValue. Negative offsets are allowed, but the square scale factor itself must be >= 0.
Solutions
- Clamp or validate squareScale to >= 0 before calling SetCustomSquareScaling
- If negative input is meaningful, treat it as invalid input in the UI and reject it
- Catch ArgumentOutOfRangeException and surface a validation message
Example fix
// before scaling.SetCustomSquareScaling(userScale); // after scaling.SetCustomSquareScaling(Math.Max(0, userScale));
Defensive patterns
Strategy: validation
Validate before calling
if (squareScale < 0) throw new ArgumentException("squareScale must be non-negative", nameof(squareScale)); Type guard
static bool IsValidSquareScale(int v) => v >= 0;
Try / catch
try { scaling.SetCustomSquareScaling(value); }
catch (ArgumentOutOfRangeException ex) { ShowValidationError(ex.ParamName); } Prevention
- Clamp UI scaling inputs to >= 0
- Validate computed values before passing them in
- Use numeric up/down controls with MinValue=0
When it happens
Trigger: Calling pageScaling.SetCustomSquareScaling with a negative integer, typically from unvalidated user input or a computed difference that went negative.
Common situations: Custom print dialogs where the user can type or nudge a scaling value below zero; subtracting percentages that produce negative results.
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
- ArgumentException.PositiveValue (Parameter 'value')
- 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/164f3024e4640e8b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageScaling.cs:523
}
#endregion Public Properties
#region Public Methods
/// <summary>
/// Sets page scaling setting to custom square scaling.
/// </summary>
/// <param name="squareScale">custom square scaling percentage</param>
/// <exception cref="ArgumentOutOfRangeException">
/// "squareScale" is not non-negative value.
/// </exception>
public void SetCustomSquareScaling(int squareScale)
{
// Scaling percentage value must be non-negative. We do allow negative scaling offset values.
if (squareScale < 0)
{
throw new ArgumentOutOfRangeException(nameof(squareScale),
PTUtility.GetTextFromResource("ArgumentException.NonNegativeValue"));
}
// Remove all XML content related to PageScaling feature
// any way to avoid redundant NotifyPropertyChanged calls?
ClearSetting();
this[PrintSchemaTags.Framework.OptionNameProperty] = (int)PageScaling.CustomSquare;
this[PrintSchemaTags.Keywords.PageScalingKeys.CustomSquareScale] = squareScale;
}
/// <summary>
/// Converts the page scaling setting to human-readable string.
/// </summary>
/// <returns>A string that represents this page scaling setting.</returns>
public override string ToString()
{View on GitHub (pinned to 81131a70a4)