{"record":{"id":"589a7defdf619300","repo":"dotnet/wpf","slug":"propertyofclasscannotbenull-cultureinfo-textrunproperties","errorCode":null,"errorMessage":"PropertyOfClassCannotBeNull (CultureInfo, TextRunProperties)","messagePattern":"PropertyOfClassCannotBeNull \\(CultureInfo, TextRunProperties\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextRunCacheImp.cs","lineNumber":128,"sourceCode":"                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.\n                //                \n\n                // Move the rider to the end of the current run\n                textRunSpanRider.At(cpFetch + textRun.Length - 1);\n                _latestPosition = textRunSpanRider.SpanPosition;","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextRunCacheImp.cs#L110-L146","documentation":"FetchTextRun maps properties.CultureInfo through CultureMapper.GetSpecificCulture and throws ArgumentException(SR.PropertyOfClassCannotBeNull with CultureInfo/TextRunProperties) when the resulting specific culture is null. A concrete culture is required for shaping, measurement, and line-breaking.","triggerScenarios":"TextRun.Properties.CultureInfo is null or a neutral culture (e.g. \"en\" not \"en-US\") that CultureMapper cannot map to a specific culture.","commonSituations":"Threads with no culture set (CultureInfo.CurrentCulture null in defaults); assigning neutral cultures to runs; deserialized properties losing culture info.","solutions":["Set CultureInfo to a specific culture (e.g. new CultureInfo(\"en-US\")) on the run properties","Use CultureInfo.InvariantCulture-derived specific culture or CultureInfo.CurrentUICulture if neutral","Pre-validate with CultureMapper.GetSpecificCulture in your TextSource before returning the run"],"exampleFix":"// before\nprops.CultureInfo = new CultureInfo(\"en\"); // neutral\n// after\nprops.CultureInfo = new CultureInfo(\"en-US\"); // specific","handlingStrategy":"validation","validationCode":"var specific = CultureMapper.GetSpecificCulture(run.Properties.CultureInfo);\nif (specific == null) run.Properties.CultureInfo = new CultureInfo(\"en-US\");","typeGuard":"bool HasSpecificCulture(TextRunProperties p) => CultureMapper.GetSpecificCulture(p.CultureInfo) != null;","tryCatchPattern":"try { formatter.FormatLine(...); } catch (ArgumentException) { /* set a specific culture and retry */ }","preventionTips":["Always assign specific (not neutral) cultures to run properties","Default CultureInfo from the thread's CurrentCulture when unspecified"],"tags":["wpf","text-formatting","invalid-argument","cultureinfo"],"backgroundTag":"invalid-argument-value","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"}