{"record":{"id":"fe9d8d9a4d9c572e","repo":"dotnet/wpf","slug":"sr-format-sr-invalidstringvirtualizationcachelength-s","errorCode":null,"errorMessage":"SR.Format(SR.InvalidStringVirtualizationCacheLength, s)","messagePattern":"SR\\.Format\\(SR\\.InvalidStringVirtualizationCacheLength, s\\)","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLengthConverter.cs","lineNumber":212,"sourceCode":"                }\n\n                lengths[i] = Double.Parse(th.GetCurrentToken(), cultureInfo);\n                i++;\n            }\n\n            // We have a reasonable interpreation for one value (all four edges), two values (horizontal, vertical),\n            // and four values (left, top, right, bottom).\n            switch (i)\n            {\n                case 1:\n                    return new VirtualizationCacheLength(lengths[0]);\n\n                case 2:\n                    // Should allowInfinity be false ??? (Rob)\n                    return new VirtualizationCacheLength(lengths[0], lengths[1]);\n            }\n\n            throw new FormatException(SR.Format(SR.InvalidStringVirtualizationCacheLength, s));\n        }\n\n    #endregion\n    }\n}\n\n","sourceCodeStart":194,"sourceCodeEnd":219,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLengthConverter.cs#L194-L219","documentation":"VirtualizationCacheLengthConverter.FromString throws FormatException (InvalidStringVirtualizationCacheLength) when a string cannot be parsed as 1 or 2 space/comma-separated values (e.g. it splits into 3+ tokens or zero tokens). Only forms like \"5\" or \"2 3\" are accepted.","triggerScenarios":"Setting VirtualizingPanel.CacheLength=\"1 2 3\" (three values) or an empty/garbage string like \"a b c\" in XAML or via TypeConverter.ConvertFrom.","commonSituations":"XAML typos in CacheLength attributes, copy-pasted values with extra separators, or locale-dependent number strings with unexpected characters.","solutions":["Provide at most two numbers in the string: one value applies to both cache extents, two values for CacheLength/CacheLengthUnit pairs before/after the viewport.","Remove extra whitespace-separated tokens from the attribute value.","Use the CacheLengthUnit-qualified form only via the documented syntax (e.g. \"1,2\")."],"exampleFix":"<!-- before -->\n<VirtualizingPanel.CacheLength>1 2 3</VirtualizingPanel.CacheLength>\n<!-- after -->\n<VirtualizingPanel.CacheLength>1 2</VirtualizingPanel.CacheLength>","handlingStrategy":"validation","validationCode":"var parts = s.Split(new[]{' ', ','}, StringSplitOptions.RemoveEmptyEntries);\nif (parts.Length >= 1 && parts.Length <= 2 && parts.All(p => double.TryParse(p, NumberStyles.Float, CultureInfo.InvariantCulture, out _))) { /* safe to convert */ }","typeGuard":null,"tryCatchPattern":"try { var len = (VirtualizationCacheLength)converter.ConvertFrom(s); } catch (FormatException) { var len = new VirtualizationCacheLength(0); }","preventionTips":["Keep CacheLength XAML values to one or two numbers","Avoid extra separators or tokens in the attribute","Use invariant culture when parsing numeric strings"],"tags":["wpf","typeconverter","format-exception","xaml"],"backgroundTag":"invalid-argument-format","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"}