{"record":{"id":"3624add8fce60f11","repo":"dotnet/wpf","slug":"ptutility-gettextfromresource-argumentexception","errorCode":null,"errorMessage":"PTUtility.GetTextFromResource(\"ArgumentException.PositiveValue\")","messagePattern":"PTUtility\\.GetTextFromResource\\(\"ArgumentException\\.PositiveValue\"\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/DocumentNUp.cs","lineNumber":518,"sourceCode":"        /// Gets or sets the value of number of logical pages per physical sheet.\n        /// </summary>\n        /// <remarks>\n        /// If this setting is not specified yet, getter will return <see cref=\"PrintSchema.UnspecifiedIntValue\"/>.\n        /// </remarks>\n        /// <exception cref=\"ArgumentOutOfRangeException\">\n        /// The value to set is not a positive integer.\n        /// </exception>\n        public int PagesPerSheet\n        {\n            get\n            {\n                return this[PrintSchemaTags.Keywords.NUpKeys.PagesPerSheet];\n            }\n            set\n            {\n                if (value <= 0)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value),\n                                  PTUtility.GetTextFromResource(\"ArgumentException.PositiveValue\"));\n                }\n\n                this[PrintSchemaTags.Keywords.NUpKeys.PagesPerSheet] = value;\n            }\n        }\n\n        /// <summary>\n        /// Gets a <see cref=\"NUpPresentationDirectionSetting\"/> object that specifies the document NUp presentation direction setting.\n        /// </summary>\n        public NUpPresentationDirectionSetting PresentationDirection\n        {\n            get\n            {\n                if (_presentationDirection == null)\n                {\n                    _presentationDirection = new NUpPresentationDirectionSetting(this._ownerPrintTicket)\n                    {","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/DocumentNUp.cs#L500-L536","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ndocNUp.NUpSetting = pagesPerSheet; // pagesPerSheet may be 0\n// after\nif (pagesPerSheet > 0)\n{\n    docNUp.NUpSetting = pagesPerSheet;\n}","handlingStrategy":"validation","validationCode":"if (pagesPerSheet <= 0) throw new ArgumentOutOfRangeException(nameof(pagesPerSheet));","typeGuard":"bool IsValidPagesPerSheet(int v) => v > 0;","tryCatchPattern":"catch (ArgumentOutOfRangeException) { /* clamp to 1 or reject input */ }","preventionTips":["Validate integer settings parsed from config/UI before applying them to PrintTicket.","Use > 0 checks for all counts/quantities in print configuration."],"tags":["print-ticket","printconfig","argument-out-of-range","wpf"],"backgroundTag":"value-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}