{"record":{"id":"df891dc18f83fc90","repo":"dotnet/wpf","slug":"sr-format-sr-xmllanggetculturefailure-lowercasetag","errorCode":null,"errorMessage":"SR.Format(SR.XmlLangGetCultureFailure, lowerCaseTag)","messagePattern":"SR\\.Format\\(SR\\.XmlLangGetCultureFailure, lowerCaseTag\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Markup/XmlLanguage.cs","lineNumber":200,"sourceCode":"                // xml:lang=\"und\"\n                // see http://www.w3.org/International/questions/qa-no-language\n                //\n                // Just treat it the same as xml:lang=\"\"\n                if(string.Equals(lowerCaseTag, \"und\", StringComparison.Ordinal))\n                {\n                    lowerCaseTag = String.Empty;\n                }            \n                \n                try\n                {\n                    // Even if we previously failed to find an EquivalentCulture, we retry, if only to\n                    //   capture inner exception.\n                    _equivalentCulture = CultureInfo.GetCultureInfoByIetfLanguageTag(lowerCaseTag);\n                }\n                catch (ArgumentException e)\n                {\n                    _equivalentCultureFailed = true;\n                    throw new InvalidOperationException(SR.Format(SR.XmlLangGetCultureFailure, lowerCaseTag), e);\n                }\n            }\n\n            return _equivalentCulture;\n        }\n        \n        /// <summary>\n        ///     Finds the most-closely-related non-neutral registered CultureInfo, if one is available.\n        /// </summary>\n        /// <returns>\n        ///     A non-Neutral CultureInfo.\n        /// </returns>\n        /// <exception cref=\"InvalidOperationException\">\n        ///    There is no related non-Neutral CultureInfo registered.\n        /// </exception>\n        /// <remarks>\n        ///    Will return CultureInfo.InvariantCulture if-and-only-if this.Equals(XmlLanguage.Empty).\n        ///    Finds the registered CultureInfo matching the longest-possible prefix of this XmlLanguage.","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Markup/XmlLanguage.cs#L182-L218","documentation":"XmlLanguage.GetEquivalentCulture converts the IETF language tag into a CultureInfo via GetCultureInfoByIetfLanguageTag; when the tag is not a registered/valid language tag the underlying call throws ArgumentException, which is rethrown as an InvalidOperationException with the offending tag in the message and the original exception as InnerException.","triggerScenarios":"Calling GetEquivalentCulture on an XmlLanguage whose tag is empty, malformed, or not recognized by the OS culture data (e.g. \"xx-YY\" never registered, custom tags like \"qps-plocm\" on older systems, or an empty xml:lang).","commonSituations":"Deserializing localized documents where xml:lang was authored with made-up or legacy tags; user-supplied language strings passed into XmlLanguage.GetLanguage then converted; OS culture data differences across .NET/Windows versions making a tag valid on one machine and not another.","solutions":["Use TryGetEquivalentCulture instead of GetEquivalentCulture and handle the false return gracefully","Pre-validate the tag with CultureInfo.GetCultures(CultureTypes.AllCultures) matching on IetfLanguageTag before calling","Normalize the tag (lowercase, well-formed subtags) via XmlLanguage.GetLanguage before conversion","Catch InvalidOperationException and fall back to InvariantCulture or a parent-language tag (e.g. \"en\" for \"en-XYZ\")"],"exampleFix":"// before\nCultureInfo ci = xmlLang.GetEquivalentCulture(); // throws for unknown tag\n// after\nif (!xmlLang.TryGetEquivalentCulture(out CultureInfo ci))\n    ci = CultureInfo.InvariantCulture;","handlingStrategy":"fallback","validationCode":"bool tagKnown = CultureInfo.GetCultures(CultureTypes.AllCultures).Any(c => c.IetfLanguageTag == xmlLang.IetfLanguageTag);","typeGuard":"static bool HasEquivalentCulture(XmlLanguage lang) => lang != null && CultureInfo.GetCultures(CultureTypes.AllCultures).Any(c => c.IetfLanguageTag == lang.IetfLanguageTag);","tryCatchPattern":"try { ci = xmlLang.GetEquivalentCulture(); }\ncatch (InvalidOperationException ex) { ci = CultureInfo.InvariantCulture; /* log ex.InnerException */ }","preventionTips":["Prefer TryGetEquivalentCulture for untrusted tags","Normalize language tags to lowercase before use","Fall back to parent tags or InvariantCulture for unknown tags","Test on target OS versions since culture data varies"],"tags":["wpf","globalization","culture","ietf-language-tag"],"backgroundTag":"invalid-culture-tag","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"}