{"record":{"id":"3ec9fd7f87843852","repo":"dotnet/wpf","slug":"sr-propertyofclassmustbegreaterthanzero-fontrenderingemsize","errorCode":null,"errorMessage":"SR.PropertyOfClassMustBeGreaterThanZero (FontRenderingEmSize, TextRunProperties)","messagePattern":"SR\\.PropertyOfClassMustBeGreaterThanZero \\(FontRenderingEmSize, TextRunProperties\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextRunCacheImp.cs","lineNumber":118,"sourceCode":"            if(textRun == null)\n            {\n                // run not already cached, fetch new run and cache it\n\n                textRun = settings.TextSource.GetTextRun(cpFetch);\n\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 ","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextRunCacheImp.cs#L100-L136","documentation":"FetchTextRun requires FontRenderingEmSize to be strictly positive. It throws ArgumentException(SR.PropertyOfClassMustBeGreaterThanZero with FontRenderingEmSize/TextRunProperties) when the em size is zero or negative, since font size must be a positive real value to measure text.","triggerScenarios":"TextRun.Properties.FontRenderingEmSize <= 0 returned by a TextSource; font size computed from data (e.g. zoom/scale) that collapsed to 0 or became negative.","commonSituations":"Zoom or scale factor of 0 applied to font size; uninitialized font size field defaulting to 0; data-binding producing NaN/0 sizes.","solutions":["Set FontRenderingEmSize to a positive value (e.g. > 0, at least 0.1) in your TextRunProperties","Clamp computed font sizes to a small positive minimum before creating runs","Validate run properties in your TextSource before returning the run"],"exampleFix":"// before\nprops.FontRenderingEmSize = fontSize; // fontSize may be 0\n// after\nprops.FontRenderingEmSize = Math.Max(fontSize, 0.1);","handlingStrategy":"validation","validationCode":"if (run.Properties == null || run.Properties.FontRenderingEmSize <= 0) throw new ArgumentException(\"FontRenderingEmSize must be > 0\");","typeGuard":"bool HasValidEmSize(TextRun r) => r?.Properties?.FontRenderingEmSize > 0;","tryCatchPattern":"try { formatter.FormatLine(...); } catch (ArgumentException) { /* clamp em size and retry */ }","preventionTips":["Clamp computed font sizes to a positive minimum","Guard zoom/scale math so size never reaches 0 or negative"],"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"}