{"record":{"id":"a456cb3715b08158","repo":"dotnet/wpf","slug":"sr-format-sr-xmllangmalformed-ietflanguagetag","errorCode":null,"errorMessage":"SR.Format(SR.XmlLangMalformed, ietfLanguageTag)","messagePattern":"SR\\.Format\\(SR\\.XmlLangMalformed, ietfLanguageTag\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Markup/XmlLanguage.cs","lineNumber":792,"sourceCode":"                        ThrowParseException(ietfLanguageTag);\n                    }\n                }\n            }\n        }\n\n        private static bool IsLowerAlpha(int c)\n        {\n            return (c >= 'a' && c <= 'z');\n        }\n\n        private static bool IsDigit(int c)\n        {\n            return c >= '0' && c <= '9';\n        }\n\n        private static void ThrowParseException(string ietfLanguageTag)\n        {\n             throw new ArgumentException(SR.Format(SR.XmlLangMalformed, ietfLanguageTag), nameof(ietfLanguageTag));\n        }\n\n        // throws if there is a non-7-bit ascii character\n        private static string AsciiToLower(string tag)\n        {\n            int length = tag.Length;\n\n            for (int i = 0; i < length; i++)\n            {\n                if (tag[i] > 127)\n                {\n                    ThrowParseException(tag);\n                }\n            }\n\n            return tag.ToLowerInvariant();\n        }\n}","sourceCodeStart":774,"sourceCodeEnd":810,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Markup/XmlLanguage.cs#L774-L810","documentation":"XmlLanguage.Parse / GetLanguage received an IETF language tag that does not conform to BCP-47 subtag syntax (e.g. empty, illegal or non-7-bit-ASCII characters, malformed subtags). ThrowParseException wraps the offending tag in an ArgumentException.","triggerScenarios":"XmlLanguage.GetLanguage(tag) or Parse with tags containing non-ASCII characters, invalid characters in subtags, leading/trailing hyphens, or empty strings.","commonSituations":"Passing user-entered or OS-supplied locale strings; using display names ('English (US)') instead of tags ('en-us'); non-7-bit-ASCII characters from copy-paste.","solutions":["Validate the tag matches BCP-47 syntax (letters/digits separated by single hyphens) before calling GetLanguage","Source tags from CultureInfo.IetfLanguageTag or Name instead of display names","Normalize case and strip whitespace; catch ArgumentException for tolerant parsing of user input"],"exampleFix":"// before\nvar lang = XmlLanguage.GetLanguage(userInput); // throws on 'de(1)'\n// after\nif (System.Text.RegularExpressions.Regex.IsMatch(userInput, \"^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$\"))\n{ var lang = XmlLanguage.GetLanguage(userInput.ToLowerInvariant()); }","handlingStrategy":"validation","validationCode":"static bool IsValidIetfTag(string tag) =>\n    !string.IsNullOrWhiteSpace(tag) &&\n    System.Text.RegularExpressions.Regex.IsMatch(tag, \"^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Source tags from CultureInfo.IetfLanguageTag, not display names","Normalize case and strip whitespace before parsing","Wrap GetLanguage in try/catch ArgumentException for user input"],"tags":["wpf","localization","argumentexception","bcp47"],"backgroundTag":"invalid-argument-format","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"}