{"record":{"id":"e3ef12431a166cdd","repo":"dotnet/wpf","slug":"sr-invalidctorparameternonan","errorCode":null,"errorMessage":"SR.InvalidCtorParameterNoNaN","messagePattern":"SR\\.InvalidCtorParameterNoNaN","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLength.cs","lineNumber":68,"sourceCode":"        /// Constructor, initializes the CacheBeforeViewport and the CacheAfterViewport to their sizes. Units are specified as a seperate VisualizationCacheLengthUnit property.\n        /// </summary>\n        /// <param name=\"cacheBeforeAndAfterViewport\">Value to be stored by this VirtualizationCacheLength \n        /// instance as the cacheBeforeViewport and cacheAfterViewport.</param>\n        /// <exception cref=\"ArgumentException\">\n        /// If <c>cacheBeforeAndAfterViewport</c> parameter is <c>double.NaN</c>\n        /// or <c>cacheBeforeAndAfterViewport</c> parameter is <c>double.NegativeInfinity</c>\n        /// or <c>cacheBeforeAndAfterViewport</c> parameter is <c>double.PositiveInfinity</c>.\n        /// </exception>\n        public VirtualizationCacheLength(double cacheBeforeAndAfterViewport)\n            : this(cacheBeforeAndAfterViewport, cacheBeforeAndAfterViewport)\n        {\n        }\n\n        public VirtualizationCacheLength(double cacheBeforeViewport, double cacheAfterViewport)\n        {\n            if (double.IsNaN(cacheBeforeViewport))\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterNoNaN, \"cacheBeforeViewport\"));\n            }\n\n            if (double.IsNaN(cacheAfterViewport))\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterNoNaN, \"cacheAfterViewport\"));\n            }\n\n            _cacheBeforeViewport = cacheBeforeViewport;\n            _cacheAfterViewport = cacheAfterViewport;\n        }\n\n        #endregion Constructors\n\n        //------------------------------------------------------\n        //\n        //  Public Methods\n        //\n        //------------------------------------------------------","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLength.cs#L50-L86","documentation":"The two-parameter VirtualizationCacheLength constructor throws ArgumentException (InvalidCtorParameterNoNaN) when cacheBeforeViewport is NaN. NaN is rejected because virtualization cache sizes must be finite pixel/item counts.","triggerScenarios":"Calling new VirtualizationCacheLength(double.NaN, x), commonly with a value produced by double division 0/0, an uninitialized double from a binding, or Math operations that yield NaN.","commonSituations":"Computing cache length dynamically (e.g. dividing viewport size by item size when the viewport is 0) and feeding the NaN result into the constructor or into VirtualizingPanel.CacheLength.","solutions":["Validate the value with double.IsNaN before constructing and substitute a sane default.","Fix the computation that yields NaN (guard against division by zero).","Use double.IsFinite to also exclude infinities if appropriate for your scenario."],"exampleFix":"// before\nvar len = new VirtualizationCacheLength(itemWidth / viewportWidth, 0);\n// after\nvar ratio = viewportWidth > 0 ? itemWidth / viewportWidth : 1;\nvar len = new VirtualizationCacheLength(ratio, 0);","handlingStrategy":"validation","validationCode":"if (!double.IsNaN(cacheBeforeViewport)) { var len = new VirtualizationCacheLength(cacheBeforeViewport, cacheAfterViewport); }","typeGuard":"bool IsValidCacheLength(double v) => !double.IsNaN(v);","tryCatchPattern":"try { var len = new VirtualizationCacheLength(before, after); } catch (ArgumentException) { var len = new VirtualizationCacheLength(0, 0); }","preventionTips":["Guard divisions that feed cache lengths","Sanitize binding/computed doubles before constructing","Prefer double.IsFinite checks for extra safety"],"tags":["wpf","virtualization","nan","constructor"],"backgroundTag":"invalid-constructor-argument","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"}