{"record":{"id":"90b6bf6bcd4a891f","repo":"dotnet/wpf","slug":"argumentexception-positivevalue-parameter-value","errorCode":null,"errorMessage":"ArgumentException.PositiveValue (Parameter 'value')","messagePattern":"ArgumentException\\.PositiveValue \\(Parameter 'value'\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageResolution.cs","lineNumber":348,"sourceCode":"        /// Gets or sets the page resolution setting's X component.\n        /// </summary>\n        /// <remarks>\n        /// If this component 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 ResolutionX\n        {\n            get\n            {\n                return this[PrintSchemaTags.Keywords.PageResolutionKeys.ResolutionX];\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.PageResolutionKeys.ResolutionX] = value;\n            }\n        }\n\n        /// <summary>\n        /// Gets or sets the page resolution setting's Y component.\n        /// </summary>\n        /// <remarks>\n        /// If this component 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 ResolutionY\n        {","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageResolution.cs#L330-L366","documentation":"PageResolutionSetting's ResolutionX setter requires a strictly positive resolution; assigning 0 or a negative DPI value throws ArgumentOutOfRangeException with the resource message ArgumentException.PositiveValue. ResolutionX is stored in the ticket under the PageResolutionkeys.ResolutionX property.","triggerScenarios":"Setting PageResolution.X (e.g. via a custom PageResolution on PrintTicket) to 0 or a negative number.","commonSituations":"Reading DPI from config that defaults to 0; computing resolution from device values that failed to load; copy/paste errors swapping width/height/zero placeholders.","solutions":["Ensure the X resolution is > 0 before assigning.","Only use PageResolution values reported by queue.GetPrintCapabilities().PageResolutions.","Guard with a check or Math.Max(1, x) before assignment.","Catch ArgumentOutOfRangeException and fall back to the queue's default resolution."],"exampleFix":"// before\nresolution.X = dpiX; // may be 0\n// after\nif (dpiX > 0) resolution.X = dpiX;\nelse resolution = queue.DefaultPrintTicket.PageResolution;","handlingStrategy":"validation","validationCode":"if (dpiX > 0)\n    resolution.X = dpiX;","typeGuard":"bool IsValidResolutionX(object v) => v is int i && i > 0;","tryCatchPattern":"try { resolution.X = dpiX; }\ncatch (ArgumentOutOfRangeException) { resolution = queue.DefaultPrintTicket.PageResolution; }","preventionTips":["Take resolutions from queue.GetPrintCapabilities().PageResolutions","Check config-loaded DPI values for zero before applying","Treat 0/unloaded DPI as 'not set' instead of assigning it"],"tags":["wpf","printing","argumentoutofrange","resolution"],"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-21T21:30:21.729Z"}