{"record":{"id":"4d5d5997a6dc64ed","repo":"dotnet/wpf","slug":"sr-format-sr-invalidctorparameternonegative-value","errorCode":null,"errorMessage":"SR.Format(SR.InvalidCtorParameterNoNegative, \"value\")","messagePattern":"SR\\.Format\\(SR\\.InvalidCtorParameterNoNegative, \"value\"\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs","lineNumber":111,"sourceCode":"        /// or <c>value</c> parameter is <c>double.PositiveInfinity</c>.\n        /// or <c>value</c> parameter is <c>negative</c>.\n        /// </exception>\n        public FigureLength(double value, FigureUnitType type)\n        {\n            double maxColumns = PTS.Restrictions.tscColumnRestriction;\n            double maxPixel = Math.Min(1000000, PTS.MaxPageSize);\n\n            if (double.IsNaN(value))\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterNoNaN, \"value\"));\n            }\n            if (double.IsInfinity(value))\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterNoInfinity, \"value\"));\n            }\n            if (value < 0.0)\n            {\n                throw new ArgumentOutOfRangeException(SR.Format(SR.InvalidCtorParameterNoNegative, \"value\"));\n            }\n            if (    type != FigureUnitType.Auto\n                &&  type != FigureUnitType.Pixel\n                &&  type != FigureUnitType.Column\n                &&  type != FigureUnitType.Content\n                &&  type != FigureUnitType.Page   )\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterUnknownFigureUnitType, \"type\"));\n            }\n            if (type is FigureUnitType.Content or FigureUnitType.Page)\n            {\n                ArgumentOutOfRangeException.ThrowIfGreaterThan(value, 1.0);\n            }\n\n            if (type == FigureUnitType.Column)\n            {\n                ArgumentOutOfRangeException.ThrowIfGreaterThan(value, maxColumns);\n            }","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs#L93-L129","documentation":"The FigureLength constructor rejects a negative value (value < 0.0) with ArgumentOutOfRangeException. Figure lengths are non-negative quantities; Auto/Pixel/Column/Content/Page all require value >= 0.","triggerScenarios":"Calling new FigureLength(x, type) with x < 0.0 for any FigureUnitType — e.g. subtracting margins into a computed size.","commonSituations":"Computed sizes going negative after subtraction; parsing user input without validation; sign errors in layout math.","solutions":["Clamp with Math.Max(0, value) before constructing the FigureLength.","Validate the input value before the call and reject or correct negatives at the source.","Fix the upstream calculation that produces a negative size."],"exampleFix":"// before\nvar length = new FigureLength(available - used, FigureUnitType.Pixel); // may be negative\n\n// after\nvar length = new FigureLength(Math.Max(0, available - used), FigureUnitType.Pixel);","handlingStrategy":"validation","validationCode":"if (value < 0.0)\n    throw new ArgumentOutOfRangeException(nameof(value), \"FigureLength value must be non-negative.\");","typeGuard":"bool IsNonNegative(double v) => !double.IsNaN(v) && v >= 0.0;","tryCatchPattern":"try { var len = new FigureLength(value, unit); }\ncatch (ArgumentOutOfRangeException) { /* clamp to 0 or recompute the size */ }","preventionTips":["Clamp computed sizes with Math.Max(0, x) before constructing lengths.","Validate user/parsed input for negativity at ingestion.","Review subtraction-based layout math for sign errors."],"tags":["wpf","argument-out-of-range","constructor","layout"],"backgroundTag":"argument-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"}