dotnet/wpf · error · ArgumentException
SR.SpecificNumberCultureRequired
Error message
SR.SpecificNumberCultureRequired
What it means
NumberSubstitution.ThrowIfInvalidCultureOverride requires the CultureOverride to be a specific (non-neutral, non-invariant) CultureInfo; otherwise it throws ArgumentException(SR.SpecificNumberCultureRequired). CultureOverride must identify an exact culture like 'fr-FR', not 'fr' or the invariant culture.
Solutions
- Set CultureOverride to a specific culture with a region, e.g. new CultureInfo("fr-FR") instead of "fr"
- Validate before assigning: a culture is valid when it's non-null, not invariant, and not neutral (culture.IsNeutralCulture == false)
- If only a language code is available, expand it to a default specific culture (e.g. "en" -> "en-US")
- Catch ArgumentException around the property/constructor set and fall back to CultureSource-based resolution
Example fix
// before
numberSubstitution.CultureOverride = new CultureInfo("fr"); // neutral culture
// after
var culture = new CultureInfo("fr-FR"); // specific culture
numberSubstitution.CultureOverride = culture; Defensive patterns
Strategy: validation
Validate before calling
if (culture == null || culture.Equals(CultureInfo.InvariantCulture) || culture.IsNeutralCulture)
culture = CultureInfo.CreateSpecificCulture(culture?.Name ?? "en"); Type guard
bool IsValidCultureOverride(CultureInfo c) => c != null && !c.Equals(CultureInfo.InvariantCulture) && !c.IsNeutralCulture;
Try / catch
try { numberSubstitution.CultureOverride = culture; }
catch (ArgumentException ex) { log.Warn("CultureOverride must be specific, falling back", ex); numberSubstitution.CultureSource = NumberCultureSource.AsCulture; } Prevention
- Always use specific cultures ('fr-FR'), never neutral ('fr')
- Expand two-letter language codes with CultureInfo.CreateSpecificCulture
- Validate culture override whenever it originates from user input or config
When it happens
Trigger: Setting NumberSubstitution.CultureOverride to a neutral culture (e.g. new CultureInfo("fr")), CultureInfo.InvariantCulture, an empty culture, or passing such a culture to the NumberSubstitution constructor.
Common situations: Deriving the culture from a language code that only has two letters (e.g. 'en', 'de'); using Thread.CurrentThread.CurrentUICulture when it is neutral; config storing 'invariant' as the override; parsing locale strings that lost their region suffix.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.Format(SR.XmlLangGetCultureFailure, lowerCaseTag)
- SR.Format(SR.XmlLangGetSpecificCulture, _lowerCaseTag)
- ArgumentNullException("characterBufferReference.CharacterBuf…
- ArgumentNullException("textRunProperties.CultureInfo")
- ArgumentNullException("textRunProperties.Typeface")
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/6ac3cbe5e77d77bf.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/NumberSubstitution.cs:83
/// </summary>
[TypeConverter(typeof(System.Windows.CultureInfoIetfLanguageTagConverter))]
public CultureInfo CultureOverride
{
get { return _cultureOverride; }
set { _cultureOverride = ThrowIfInvalidCultureOverride(value); }
}
/// <summary>
/// Helper function to throw an exception if invalid value is specified for
/// CultureOverride property.
/// </summary>
/// <param name="culture">Culture to validate.</param>
/// <returns>The value of the culture parameter.</returns>
private static CultureInfo ThrowIfInvalidCultureOverride(CultureInfo culture)
{
if (!IsValidCultureOverride(culture))
{
throw new ArgumentException(SR.SpecificNumberCultureRequired);
}
return culture;
}
/// <summary>
/// Determines whether the specific culture is a valid value for the
/// CultureOverride property.
/// </summary>
/// <param name="culture">Culture to validate.</param>
/// <returns>Returns true if it's a valid CultureOverride, false if not.</returns>
private static bool IsValidCultureOverride(CultureInfo culture)
{
// Null culture override is OK, but otherwise it must be a specific culture.
return
(culture == null) ||
!(culture.IsNeutralCulture || culture.Equals(CultureInfo.InvariantCulture));
}
View on GitHub (pinned to 81131a70a4)