{"record":{"id":"a41f1d9d282d21a1","repo":"dotnet/wpf","slug":"argumentnullexception-textrunproperties-cultureinfo","errorCode":null,"errorMessage":"ArgumentNullException(\"textRunProperties.CultureInfo\")","messagePattern":"ArgumentNullException\\(\"textRunProperties\\.CultureInfo\"\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextCharacters.cs","lineNumber":119,"sourceCode":"        /// Internal constructor of TextContent\n        /// </summary>\n        private TextCharacters(\n            CharacterBufferReference    characterBufferReference,\n            int                         length,\n            TextRunProperties           textRunProperties\n            )\n        {\n            ArgumentOutOfRangeException.ThrowIfNegativeOrZero(length);\n            ArgumentNullException.ThrowIfNull(textRunProperties);\n\n            if (textRunProperties.Typeface == null)\n            {\n                throw new ArgumentNullException(\"textRunProperties.Typeface\");\n            }\n\n            if (textRunProperties.CultureInfo == null)\n            {\n                throw new ArgumentNullException(\"textRunProperties.CultureInfo\");\n            }\n\n            ArgumentOutOfRangeException.ThrowIfNegativeOrZero(textRunProperties.FontRenderingEmSize, \"textRunProperties.FontRenderingEmSize\");\n\n            _characterBufferReference = characterBufferReference;\n            _length = length;\n            _textRunProperties = textRunProperties;\n        }\n\n        #endregion\n\n\n        #region TextRun implementation\n        \n        /// <summary>\n        /// Character buffer\n        /// </summary>\n        public sealed override CharacterBufferReference CharacterBufferReference ","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextCharacters.cs#L101-L137","documentation":"The TextCharacters constructor also requires textRunProperties.CultureInfo to be non-null, throwing ArgumentNullException(\"textRunProperties.CultureInfo\") otherwise. CultureInfo drives script-specific shaping and digit substitution for the run.","triggerScenarios":"Constructing TextCharacters with TextRunProperties whose CultureInfo is null — typically a custom TextRunProperties implementation that sets Typeface but not CultureInfo, or CultureInfo taken from an uninitialized lookup.","commonSituations":"Custom TextSource implementations; culture derived from Thread.CurrentThread.CurrentCulture in a context where it is null; cloning run properties and dropping the culture.","solutions":["Set TextRunProperties.CultureInfo (e.g. CultureInfo.CurrentCulture or new CultureInfo(\"en-US\")) before constructing TextCharacters","Fix the custom TextRunProperties subclass to initialize CultureInfo in its constructor","Fall back to CultureInfo.InvariantCulture or CultureInfo.DefaultThreadCurrentCulture when no specific culture is known","Copy culture from the containing TextParagraphProperties when creating runs"],"exampleFix":"// before\nprops.CultureInfo = someCulture; // someCulture is null\nreturn new TextCharacters(text, 0, text.Length, props);\n// after\nprops.CultureInfo = someCulture ?? CultureInfo.CurrentCulture;\nreturn new TextCharacters(text, 0, text.Length, props);","handlingStrategy":"type-guard","validationCode":"if (props?.CultureInfo == null) props.CultureInfo = CultureInfo.CurrentCulture;","typeGuard":"bool HasValidCulture(TextRunProperties p) => p?.CultureInfo != null;","tryCatchPattern":"try { return new TextCharacters(text, 0, text.Length, props); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"textRunProperties.CultureInfo\") { props.CultureInfo = CultureInfo.CurrentCulture; return new TextCharacters(text, 0, text.Length, props); }","preventionTips":["Initialize CultureInfo in custom TextRunProperties constructors","Default to CultureInfo.CurrentCulture when the source culture is unknown","Preserve CultureInfo when cloning run properties"],"tags":["wpf","textformatting","null-argument","cultureinfo"],"backgroundTag":"null-argument","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"}