{"record":{"id":"7f35485e43c22c61","repo":"dotnet/wpf","slug":"ptutility-gettextfromresource-argumentexception-7f3548","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/PageCopyCount.cs","lineNumber":85,"sourceCode":"        /// Gets or sets the value of job copy count.\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 Value\n        {\n            get\n            {\n                return this.IntValue;\n            }\n            set\n            {\n                if (value <= 0)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value),\n                                  PTUtility.GetTextFromResource(\"ArgumentException.PositiveValue\"));\n                }\n\n                this.IntValue = value;\n            }\n        }\n\n        #endregion Public Properties\n\n        #region Public Methods\n\n        /// <summary>\n        /// Converts the job copy count setting to human-readable string.\n        /// </summary>\n        /// <returns>A string that represents this job copy count setting.</returns>\n        public override string ToString()\n        {\n            return Value.ToString(CultureInfo.CurrentCulture);","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageCopyCount.cs#L67-L103","documentation":"The JobCopyCount (copies) setting only accepts positive integers; assigning zero or a negative value throws ArgumentOutOfRangeException with a resource-loaded message. Copies count is meaningless at 0 or below, so the setter rejects it eagerly.","triggerScenarios":"Setting PrintTicket.CopyCount (JobCopyCountSetting.Value) to 0 or a negative number.","commonSituations":"Computing copy count from user input or a loop counter that starts at 0; subtracting copies (count--) before printing; config values defaulting to 0.","solutions":["Ensure the value is >= 1 before assigning CopyCount.","Clamp: Math.Max(1, computedCopies).","Validate user input at the UI layer to require a positive integer.","Wrap assignment in try/catch on ArgumentOutOfRangeException and fall back to 1 copy."],"exampleFix":"// before\nprintTicket.CopyCount = userCopies; // may be 0\n// after\nprintTicket.CopyCount = Math.Max(1, userCopies);","handlingStrategy":"validation","validationCode":"if (copies is int c && c >= 1)\n    printTicket.CopyCount = c;","typeGuard":"bool IsValidCopyCount(object v) => v is int i && i >= 1;","tryCatchPattern":"try { printTicket.CopyCount = copies; }\ncatch (ArgumentOutOfRangeException) { printTicket.CopyCount = 1; }","preventionTips":["Clamp user-supplied copy counts with Math.Max(1, n)","Validate copy-count UI inputs as positive integers","Never use loop counters that may reach 0 as copy counts"],"tags":["wpf","printing","argumentoutofrange","copies"],"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"}