{"record":{"id":"090de7d8a7ab47ff","repo":"dotnet/wpf","slug":"textobjectmetrics-widthoutofrange","errorCode":null,"errorMessage":"TextObjectMetrics_WidthOutOfRange","messagePattern":"TextObjectMetrics_WidthOutOfRange","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextStore.cs","lineNumber":2362,"sourceCode":"                    widthLeft = rightMargin - _formatWidth;\n                }\n\n                metrics = textObject.Format(_settings.Formatter.IdealToReal(widthLeft, _settings.TextSource.PixelsPerDip));\n\n                if (Double.IsPositiveInfinity(metrics.Width))\n                {\n                    // If the inline object has Width to be positive infinity, trim the width to\n                    // the maximum value that LS can handle.\n                    metrics = new TextEmbeddedObjectMetrics(\n                        _settings.Formatter.IdealToReal((Constants.IdealInfiniteWidth - currentPosition), _settings.TextSource.PixelsPerDip),\n                        metrics.Height,\n                        metrics.Baseline\n                        );\n                }\n                else if (metrics.Width > _settings.Formatter.IdealToReal((Constants.IdealInfiniteWidth - currentPosition), _settings.TextSource.PixelsPerDip))\n                {\n                    // LS cannot compute value greater than its maximum computable value\n                    throw new ArgumentException(SR.TextObjectMetrics_WidthOutOfRange);\n                }\n\n                _textObjectMetricsVector.SetReference(cpFirst, textObject.Length, metrics);\n            }\n\n            Debug.Assert(metrics != null);\n            return metrics;\n        }\n\n\n        #region ENUMERATIONS & CONST\n\n        // first negative cp of bullet marker\n        internal const int LscpFirstMarker = (-0x7FFFFFFF);\n\n        // Note: Trident uses this figure\n        internal const int TypicalCharactersPerLine = 100;\n","sourceCodeStart":2344,"sourceCodeEnd":2380,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextStore.cs#L2344-L2380","documentation":"TextStore throws ArgumentException(SR.TextObjectMetrics_WidthOutOfRange) when the formatter produces a text-object metrics width larger than the maximum computable value LS supports (IdealToReal(Constants.IdealInfiniteWidth - currentPosition)). This guards against LS returning an unrepresentable width for a text object (e.g. a TextElement/text modifiers value). It is an internal invariant guard inside TextObjectMetrics handling, not a caller-input validation.","triggerScenarios":"Calling text layout APIs (e.g. TextFormatter-based formatting through TextStore) where a text object's computed metrics width exceeds Constants.IdealInfiniteWidth measured from the current character position, typically with extremely large font sizes, extremely long unbreakable text objects, or corrupted/oversized text run data.","commonSituations":"Rendering documents with absurdly large em sizes or DIP scaling (PixelsPerDip) pushing widths beyond ideal-coordinate limits; hosting WPF text services (TSF) with pathological text objects; internal-only, rarely hit by direct developers.","solutions":["Reduce the size/extent of the text object being formatted (font size, run length) so its width stays within the ideal-coordinate maximum","Check PixelsPerDip / scaling factors and zoom levels applied to the formatting; extreme values inflate widths","Capture a minimal repro of the text content and file a WPF bug, since LS cannot compute widths beyond its maximum value","Wrap the formatting call in try-catch to fail gracefully instead of crashing the layout pass"],"exampleFix":"// before: formatting a run with fontSize = 1e6 at deep zoom\n// after: clamp scale before formatting\ndouble maxIdeal = Constants.IdealInfiniteWidth;\nif (estimatedWidth > maxIdeal) { fontSize = ComputeMaxFittingFontSize(); }","handlingStrategy":"try-catch","validationCode":"// estimate before formatting\ndouble maxIdeal = Constants.IdealInfiniteWidth - currentPosition;\ndouble maxReal = formatter.IdealToReal(maxIdeal, pixelsPerDip);\nif (estimatedTextObjectWidth > maxReal) { /* reduce font size / run length */ }","typeGuard":null,"tryCatchPattern":"try { textStore.FormatTextObject(...); }\ncatch (ArgumentException ex) when (ex.Message == SR.TextObjectMetrics_WidthOutOfRange)\n{ logger.Warn(\"Text object width exceeds LS maximum\"); FallBackToSmallerScale(); }","preventionTips":["Clamp font sizes and zoom/PixelsPerDip factors before layout","Avoid extremely long unbreakable text objects in a single run","Log estimated metrics widths in diagnostics to catch near-limit values early"],"tags":["wpf","text-formatting","argument-exception","internal-invariant"],"backgroundTag":"value-out-of-range","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"}