{"record":{"id":"bebf9e2dd936aeaa","repo":"dotnet/wpf","slug":"sr-datagridlength-infinity","errorCode":null,"errorMessage":"SR.DataGridLength_Infinity","messagePattern":"SR\\.DataGridLength_Infinity","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs","lineNumber":77,"sourceCode":"        /// <param name=\"value\">The value to hold.</param>\n        /// <param name=\"type\">The unit of <c>value</c>.</param>\n        /// <param name=\"desiredValue\"></param>\n        /// <param name=\"displayValue\"></param>\n        /// <remarks> \n        ///     <c>value</c> is ignored unless <c>type</c> is\n        ///     <c>DataGridLengthUnitType.Pixel</c> or\n        ///     <c>DataGridLengthUnitType.Star</c>\n        /// </remarks>\n        /// <exception cref=\"ArgumentException\">\n        ///     If <c>value</c> parameter is <c>double.NaN</c>\n        ///     or <c>value</c> parameter is <c>double.NegativeInfinity</c>\n        ///     or <c>value</c> parameter is <c>double.PositiveInfinity</c>.\n        /// </exception>\n        public DataGridLength(double value, DataGridLengthUnitType type, double desiredValue, double displayValue)\n        {\n            if (double.IsNaN(value) || Double.IsInfinity(value))\n            {\n                throw new ArgumentException(\n                    SR.DataGridLength_Infinity,\n                    nameof(value));\n            }\n\n            if (type != DataGridLengthUnitType.Auto &&\n                type != DataGridLengthUnitType.Pixel &&\n                type != DataGridLengthUnitType.Star &&\n                type != DataGridLengthUnitType.SizeToCells &&\n                type != DataGridLengthUnitType.SizeToHeader)\n            {\n                throw new ArgumentException(\n                    SR.DataGridLength_InvalidType, \n                    nameof(type));\n            }\n\n            if (Double.IsInfinity(desiredValue))\n            {\n                throw new ArgumentException(","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs#L59-L95","documentation":"The DataGridLength(double value, DataGridLengthUnitType type, ...) constructor throws ArgumentException (message SR.DataGridLength_Infinity) when the value parameter is NaN or infinite. DataGridLength only accepts finite pixel/unit values; special sizes (Auto, Star, SizeToCells, SizeToHeader) are expressed via the type, not via NaN/Infinity.","triggerScenarios":"new DataGridLength(double.NaN), new DataGridLength(double.PositiveInfinity), or passing NaN/Infinity as value while constructing a length for a DataGridColumn.Width.","commonSituations":"Porting GridLength code where 'Auto' was represented as double.NaN; binding a Width value from data that contains NaN; division producing Infinity before constructing the length.","solutions":["Use DataGridLength.Auto or DataGridLengthUnitType.Auto instead of NaN","Pass a finite positive double for value","Guard the input with double.IsNaN/IsInfinity before constructing","Use DataGridLength.SizeToHeader/SizeToCells for content-based sizing"],"exampleFix":"// before\ncolumn.Width = new DataGridLength(double.NaN);\n// after\ncolumn.Width = DataGridLength.Auto;","handlingStrategy":"validation","validationCode":"bool isValidLength(double v) => !double.IsNaN(v) && !double.IsInfinity(v);","typeGuard":"bool TryGetDataGridLength(double v, out DataGridLength len) { len = isValidLength(v) ? new DataGridLength(v) : DataGridLength.Auto; return isValidLength(v); }","tryCatchPattern":"try { len = new DataGridLength(value); } catch (ArgumentException) { len = DataGridLength.Auto; }","preventionTips":["Use DataGridLength.Auto for auto-sizing, not NaN","Sanitize bound width values before constructing lengths","Guard width computations against Infinity-producing math"],"tags":["wpf","datagrid","argument"],"backgroundTag":"invalid-argument-value","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"}