{"record":{"id":"c14c254f9d1b4dbb","repo":"dotnet/wpf","slug":"ptutility-gettextfromresource-argumentexception-c14c25","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/PageMediaSize.cs","lineNumber":562,"sourceCode":"                                               bool bSetValue,\n                                               double mediaSizeWidth,\n                                               double mediaSizeHeight,\n                                               bool bSetWH)\n        {\n            if (bSetValue)\n            {\n                if (value < PrintSchema.PageMediaSizeNameEnumMin ||\n                    value > PrintSchema.PageMediaSizeNameEnumMax)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value));\n                }\n            }\n\n            if (bSetWH)\n            {\n                if ( (mediaSizeWidth <= 0) || (mediaSizeHeight <= 0) )\n                {\n                    throw new ArgumentOutOfRangeException((mediaSizeWidth <= 0) ? \"mediaSizeWidth\" : \"mediaSizeHeight\",\n                                  PTUtility.GetTextFromResource(\"ArgumentException.PositiveValue\"));\n                }\n            }\n\n            // Remove all XML content related to PageMediaSize feature\n            ClearSetting();\n\n            if (bSetValue)\n            {\n                this[PrintSchemaTags.Framework.OptionNameProperty] = (int)value;\n            }\n\n            if (bSetWH)\n            {\n                this[PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeWidth] =\n                    UnitConverter.LengthValueFromDIPToMicron(mediaSizeWidth);\n                this[PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeHeight] =\n                    UnitConverter.LengthValueFromDIPToMicron(mediaSizeHeight);","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageMediaSize.cs#L544-L580","documentation":"SetFixedMediaSize (via InternalSetFixedMediaSize) accepts an explicit media size width/height; when width or height is <= 0 it throws ArgumentOutOfRangeException naming the offending parameter. Fixed media dimensions must be positive physical values.","triggerScenarios":"Calling PrintTicket.SetFixedMediaSize(width, height) with mediaSizeWidth <= 0 or mediaSizeHeight <= 0.","commonSituations":"Computing page size from uninitialized/zero variables; unit conversion mistakes producing 0; passing PageMediaSize.Width/Height of a default-constructed object.","solutions":["Verify width and height are > 0 before calling SetFixedMediaSize.","Use a PageMediaSize from queue.GetPrintCapabilities().PageMediaSizes instead of computing dimensions manually.","Guard with Math.Max or explicit checks and log/skip when dimensions are non-positive.","Catch ArgumentOutOfRangeException and fall back to the queue's default media size."],"exampleFix":"// before\nticket.SetFixedMediaSize(width, 0);\n// after\nif (width > 0 && height > 0)\n    ticket.SetFixedMediaSize(width, height);\nelse\n    ticket.PageMediaSize = queue.DefaultPrintTicket.PageMediaSize;","handlingStrategy":"validation","validationCode":"if (width > 0 && height > 0)\n    ticket.SetFixedMediaSize(width, height);","typeGuard":"bool IsValidMediaSize(double w, double h) => w > 0 && h > 0;","tryCatchPattern":"try { ticket.SetFixedMediaSize(width, height); }\ncatch (ArgumentOutOfRangeException) { ticket.PageMediaSize = queue.DefaultPrintTicket.PageMediaSize; }","preventionTips":["Prefer PageMediaSize objects from queue.GetPrintCapabilities().PageMediaSizes","Check unit conversions for zero results before applying sizes","Treat unset/zero dimensions as 'use default' rather than passing them through"],"tags":["wpf","printing","argumentoutofrange","pagesize"],"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"}