{"record":{"id":"164f3024e4640e8b","repo":"dotnet/wpf","slug":"argumentexception-nonnegativevalue-parameter-squarescale","errorCode":null,"errorMessage":"ArgumentException.NonNegativeValue (Parameter 'squareScale')","messagePattern":"ArgumentException\\.NonNegativeValue \\(Parameter 'squareScale'\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageScaling.cs","lineNumber":523,"sourceCode":"        }\n\n        #endregion Public Properties\n\n        #region Public Methods\n\n        /// <summary>\n        /// Sets page scaling setting to custom square scaling.\n        /// </summary>\n        /// <param name=\"squareScale\">custom square scaling percentage</param>\n        /// <exception cref=\"ArgumentOutOfRangeException\">\n        /// \"squareScale\" is not non-negative value.\n        /// </exception>\n        public void SetCustomSquareScaling(int squareScale)\n        {\n            // Scaling percentage value must be non-negative. We do allow negative scaling offset values.\n            if (squareScale < 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(squareScale),\n                                                      PTUtility.GetTextFromResource(\"ArgumentException.NonNegativeValue\"));\n            }\n\n            // Remove all XML content related to PageScaling feature\n            // any way to avoid redundant NotifyPropertyChanged calls?\n            ClearSetting();\n\n            this[PrintSchemaTags.Framework.OptionNameProperty] = (int)PageScaling.CustomSquare;\n\n            this[PrintSchemaTags.Keywords.PageScalingKeys.CustomSquareScale] = squareScale;\n        }\n\n        /// <summary>\n        /// Converts the page scaling setting to human-readable string.\n        /// </summary>\n        /// <returns>A string that represents this page scaling setting.</returns>\n        public override string ToString()\n        {","sourceCodeStart":505,"sourceCodeEnd":541,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageScaling.cs#L505-L541","documentation":"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.","triggerScenarios":"Calling pageScaling.SetCustomSquareScaling with a negative integer, typically from unvalidated user input or a computed difference that went negative.","commonSituations":"Custom print dialogs where the user can type or nudge a scaling value below zero; subtracting percentages that produce negative results.","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"],"exampleFix":"// before\nscaling.SetCustomSquareScaling(userScale);\n// after\nscaling.SetCustomSquareScaling(Math.Max(0, userScale));","handlingStrategy":"validation","validationCode":"if (squareScale < 0) throw new ArgumentException(\"squareScale must be non-negative\", nameof(squareScale));","typeGuard":"static bool IsValidSquareScale(int v) => v >= 0;","tryCatchPattern":"try { scaling.SetCustomSquareScaling(value); }\ncatch (ArgumentOutOfRangeException ex) { ShowValidationError(ex.ParamName); }","preventionTips":["Clamp UI scaling inputs to >= 0","Validate computed values before passing them in","Use numeric up/down controls with MinValue=0"],"tags":["wpf","printing","argumentoutofrange","scaling"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}