{"record":{"id":"6cb0b78efc17573c","repo":"dotnet/wpf","slug":"sr-format-sr-invalidctorparameternonan-cacheafterviewport","errorCode":null,"errorMessage":"SR.Format(SR.InvalidCtorParameterNoNaN, \"cacheAfterViewport\")","messagePattern":"SR\\.Format\\(SR\\.InvalidCtorParameterNoNaN, \"cacheAfterViewport\"\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLength.cs","lineNumber":73,"sourceCode":"        /// 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        //------------------------------------------------------\n\n        #region Public Methods\n\n        /// <summary>\n        /// Overloaded operator, compares 2 VirtualizationCacheLength's.","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLength.cs#L55-L91","documentation":"The two-parameter VirtualizationCacheLength constructor throws ArgumentException (InvalidCtorParameterNoNaN with \"cacheAfterViewport\") when cacheAfterViewport is NaN. Both cache extents must be finite values.","triggerScenarios":"Calling new VirtualizationCacheLength(x, double.NaN), or the value coming from parsing/computation that produced NaN (e.g. Converter output, division by zero).","commonSituations":"Setting VirtualizingPanel.CacheLength programmatically or via a converter where the cache-after value is computed and accidentally NaN.","solutions":["Check double.IsNaN(cacheAfterViewport) before constructing and use a default such as 0.","Fix the upstream calculation that produced NaN.","Centralize construction in a helper that sanitizes both parameters."],"exampleFix":"// before\nvar len = new VirtualizationCacheLength(1, computedCacheAfter);\n// after\nvar len = new VirtualizationCacheLength(1, double.IsNaN(computedCacheAfter) ? 0 : computedCacheAfter);","handlingStrategy":"validation","validationCode":"if (!double.IsNaN(cacheAfterViewport)) { 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(before, 0); }","preventionTips":["Validate both constructor parameters","Default NaN computed values before constructing","Test converters that produce cache lengths with edge inputs"],"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"}