{"record":{"id":"62ab761c3fc4784a","repo":"dotnet/wpf","slug":"sr-printdialogzeronotallowed","errorCode":null,"errorMessage":"SR.PrintDialogZeroNotAllowed","messagePattern":"SR\\.PrintDialogZeroNotAllowed","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PrintDialog.cs","lineNumber":161,"sourceCode":"        }\n\n        // the following two properties return non CLS-compliant type UInt32 (bug 1788246)\n        #pragma warning disable 3003\n\n        /// <summary>\n        /// Gets or sets the minimum page number allowed in the page ranges.\n        /// </summary>\n        public UInt32 MinPage\n        {\n            get\n            {\n                return _minPage;\n            }\n            set\n            {\n                if (_minPage <= 0)\n                {\n                    throw new System.ArgumentException(SR.Format(SR.PrintDialogZeroNotAllowed, \"MinPage\"));\n                }\n\n                _minPage = value;\n            }\n        }\n\n        /// <summary>\n        /// Gets or sets the maximum page number allowed in the page ranges.\n        /// </summary>\n        public UInt32 MaxPage\n        {\n            get\n            {\n                return _maxPage;\n            }\n            set\n            {\n                if (_maxPage <= 0)","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PrintDialog.cs#L143-L179","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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;"],"exampleFix":"// before\nprintDialog.MinPage = firstPage; // firstPage may be 0\n// after\nprintDialog.MinPage = Math.Max(1, firstPage);","handlingStrategy":"validation","validationCode":"if (candidateMinPage < 1) throw new ArgumentOutOfRangeException(nameof(candidateMinPage));\nprintDialog.MinPage = candidateMinPage;","typeGuard":"bool IsValidPageBound(int v) => v >= 1;","tryCatchPattern":"try { printDialog.MinPage = value; }\ncatch (ArgumentException ex) { /* ex.Message mentions MinPage; fall back to default 1 */ printDialog.MinPage = 1; }","preventionTips":["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."],"tags":["wpf","printdialog","argument-exception"],"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"}