{"record":{"id":"1778615a49f21f2a","repo":"dotnet/wpf","slug":"value-must-be-positive","errorCode":null,"errorMessage":"Value must be positive.","messagePattern":"Value must be positive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrtTicket_Public_Simple.cs","lineNumber":1043,"sourceCode":"                {\n                    if ((value.QualitativeResolution == null) &&\n                        (value.X == null || value.Y == null))\n                    {\n                        throw new ArgumentOutOfRangeException(nameof(value));\n                    }\n\n                    // If quality lable is specified, it needs to be valid value\n                    if ((value.QualitativeResolution != null) &&\n                        (value.QualitativeResolution < PrintSchema.PageQualitativeResolutionEnumMin ||\n                         value.QualitativeResolution > PrintSchema.PageQualitativeResolutionEnumMax))\n                    {\n                        throw new ArgumentOutOfRangeException(nameof(value));\n                    }\n\n                    // If specified, resolution X and Y values must be positive\n                    if ((value.X != null) && (value.X <= 0))\n                    {\n                        throw new ArgumentOutOfRangeException(nameof(value),\n                                      PTUtility.GetTextFromResource(\"ArgumentException.PositiveValue\"));\n                    }\n\n                    if ((value.Y != null) && (value.Y <= 0))\n                    {\n                        throw new ArgumentOutOfRangeException(nameof(value),\n                                      PTUtility.GetTextFromResource(\"ArgumentException.PositiveValue\"));\n                    }\n                }\n\n                // then adding the set operation to the cache (replacing older set operations)\n                if (_setterCache.ContainsKey(CapabilityName.PageResolution))\n                {\n                    _setterCache.Remove(CapabilityName.PageResolution);\n                }\n\n                _setterCache.Add(CapabilityName.PageResolution, value);\n","sourceCodeStart":1025,"sourceCodeEnd":1061,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrtTicket_Public_Simple.cs#L1025-L1061","documentation":"The PrintTicket.PageResolution setter requires that a specified X resolution (DPI) be strictly positive. Assigning a PageResolution whose X value is 0 or negative throws ArgumentOutOfRangeException with the message 'Value must be positive.', because zero or negative DPI cannot represent a printer resolution.","triggerScenarios":"Assigning ticket.PageResolution = new PageResolution(0, 600) or new PageResolution(-300, 600, quality), i.e. any PageResolution with X != null and X <= 0.","commonSituations":"Computing DPI from user input or division that yields 0; using default(int) = 0 as placeholder; negative values from scaling calculations on small page sizes.","solutions":["Ensure the X resolution value is a positive DPI number (>= 1) before constructing the PageResolution.","Guard the source of the DPI value (config/UI) for > 0 before assignment.","Use null for X (and supply QualitativeResolution) when the dimension is not known."],"exampleFix":"// before\nvar dpiX = CalculateDpi(); // may be 0\nticket.PageResolution = new PageResolution(dpiX, 600);\n// after\nif (dpiX > 0) ticket.PageResolution = new PageResolution(dpiX, 600);","handlingStrategy":"validation","validationCode":"if (dpiX > 0)\n    ticket.PageResolution = new PageResolution(dpiX, dpiY);\nelse\n    throw new InvalidOperationException(\"X DPI must be positive\");","typeGuard":"bool IsValidResolutionX(PageResolution r) => r == null || r.X == null || r.X > 0;","tryCatchPattern":"try { ticket.PageResolution = new PageResolution(dpiX, dpiY); }\ncatch (ArgumentOutOfRangeException ex) when (ex.Message.Contains(\"positive\"))\n{ Log.Error($\"Invalid X DPI {dpiX}\"); }","preventionTips":["Validate DPI inputs from UI/config for > 0 at the boundary.","Never use 0 as a placeholder for unknown DPI; use null or a qualitative label.","Test resolution-setting code paths with 0 and negative values."],"tags":["wpf","printing","argument-out-of-range","page-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"}