{"record":{"id":"ea31e483369be70a","repo":"dotnet/wpf","slug":"propertyofclasscannotbegreaterthan-fontrenderingemsize","errorCode":null,"errorMessage":"PropertyOfClassCannotBeGreaterThan (FontRenderingEmSize, TextRunProperties, realMaxFontRenderingEmSize)","messagePattern":"PropertyOfClassCannotBeGreaterThan \\(FontRenderingEmSize, TextRunProperties, realMaxFontRenderingEmSize\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextRunCacheImp.cs","lineNumber":123,"sourceCode":"\n                ArgumentOutOfRangeException.ThrowIfNegativeOrZero(textRun.Length, \"textRun.Length\");\n\n                Plsrun plsrun = TextRunInfo.GetRunType(textRun);\n\n                if (plsrun == Plsrun.Text || plsrun == Plsrun.InlineObject)\n                {\n                    TextRunProperties properties = textRun.Properties;\n\n                    if (properties == null)\n                        throw new ArgumentException(SR.TextRunPropertiesCannotBeNull);\n\n                    if (properties.FontRenderingEmSize <= 0)\n                        throw new ArgumentException(SR.Format(SR.PropertyOfClassMustBeGreaterThanZero, \"FontRenderingEmSize\", \"TextRunProperties\"));\n\n                    double realMaxFontRenderingEmSize = Constants.RealInfiniteWidth / Constants.GreatestMutiplierOfEm;\n\n                    if (properties.FontRenderingEmSize > realMaxFontRenderingEmSize)\n                        throw new ArgumentException(SR.Format(SR.PropertyOfClassCannotBeGreaterThan, \"FontRenderingEmSize\", \"TextRunProperties\", realMaxFontRenderingEmSize));\n\n                    CultureInfo culture = CultureMapper.GetSpecificCulture(properties.CultureInfo);\n\n                    if (culture == null)\n                        throw new ArgumentException(SR.Format(SR.PropertyOfClassCannotBeNull, \"CultureInfo\", \"TextRunProperties\"));\n\n                    if (properties.Typeface == null)\n                        throw new ArgumentException(SR.Format(SR.PropertyOfClassCannotBeNull, \"Typeface\", \"TextRunProperties\"));\n                }\n\n\n                //\n                // TextRun is specifial to SpanVector because TextRun also encodes position which needs to be \n                // consistent with the positions encoded by SpanVector. In run cache, the begining of a span \n                // should always correspond to the begining of a cached text run. If the end of the currently fetched \n                // run overlaps with the begining of an already cached run, the begining of the cached run needs to be \n                // adjusted as well as its span. Because we can't gurantee the correctness of the overlapped range \n                // so we'll simply remove the overlapped runs here.","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextRunCacheImp.cs#L105-L141","documentation":"FetchTextRun caps FontRenderingEmSize at Constants.RealInfiniteWidth / Constants.GreatestMutiplierOfEm to keep layout arithmetic safe. It throws ArgumentException(SR.PropertyOfClassCannotBeGreaterThan with FontRenderingEmSize, TextRunProperties, max) when the em size exceeds that maximum.","triggerScenarios":"TextRun.Properties.FontRenderingEmSize larger than the maximum allowed (RealInfiniteWidth divided by GreatestMutiplierOfEm), returned by a TextSource during formatting.","commonSituations":"Enormous scale/zoom factors applied to text; unbounded data-driven font sizes; missing clamping after transformation math.","solutions":["Clamp FontRenderingEmSize to Constants.RealInfiniteWidth / Constants.GreatestMutiplierOfEm before creating the run","Sanitize scale factors so em size stays within the allowed maximum","Validate in your TextRunProperties setter to reject oversized em sizes early"],"exampleFix":"// before\nprops.FontRenderingEmSize = scale * 1000000; // may exceed max\n// after\nvar max = Constants.RealInfiniteWidth / Constants.GreatestMutiplierOfEm;\nprops.FontRenderingEmSize = Math.Min(scale * baseSize, max);","handlingStrategy":"validation","validationCode":"var max = Constants.RealInfiniteWidth / Constants.GreatestMutiplierOfEm;\nif (run.Properties.FontRenderingEmSize > max) run.Properties.FontRenderingEmSize = max;","typeGuard":"bool EmSizeWithinMax(TextRunProperties p) => p.FontRenderingEmSize <= Constants.RealInfiniteWidth / Constants.GreatestMutiplierOfEm;","tryCatchPattern":"try { formatter.FormatLine(...); } catch (ArgumentException) { /* clamp em size and retry */ }","preventionTips":["Clamp em sizes to the library maximum before creating runs","Bound scale/zoom factors applied to text"],"tags":["wpf","text-formatting","argument-out-of-range","font-size"],"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"}