{"record":{"id":"0e042dec6a143214","repo":"dotnet/wpf","slug":"sr-format-sr-requiresexplicitculture-targetproperty-name","errorCode":null,"errorMessage":"SR.Format(SR.RequiresExplicitCulture, TargetProperty.Name)","messagePattern":"SR\\.Format\\(SR\\.RequiresExplicitCulture, TargetProperty\\.Name\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpressionBase.cs","lineNumber":1271,"sourceCode":"\n                // if that doesn't work, use target element's xml:lang property\n                if (_culture == null)\n                {\n                    DependencyObject target = TargetElement;\n                    if (target != null)\n                    {\n                        if (IsInTransfer && (TargetProperty == FrameworkElement.LanguageProperty))\n                        {\n                            // A binding for the Language property needs the value\n                            // of the Language property.  This circularity is not\n                            // supported (bug 1274874).\n                            if (TraceData.IsEnabled)\n                            {\n                                TraceData.TraceAndNotify(TraceEventType.Critical, TraceData.RequiresExplicitCulture, this,\n                                    traceParameters: new object[] { TargetProperty.Name, this });\n                            }\n\n                            throw new InvalidOperationException(SR.Format(SR.RequiresExplicitCulture, TargetProperty.Name));\n                        }\n\n                        // cache CultureInfo since requerying an inheritable property on every Transfer/Update can be quite expensive\n                        // CultureInfo DP rarely changes once a XAML document is loaded.\n                        // To be 100% correct, changes to the CultureInfo attached DP should be tracked\n                        // and cause a re-evaluation of this binding.\n                        _culture = ((XmlLanguage) target.GetValue(FrameworkElement.LanguageProperty)).GetSpecificCulture();\n                    }\n                }\n            }\n            return (CultureInfo)_culture;\n        }\n\n        /// <summary> Culture has changed.  Re-fetch the value with the new culture. </summary>\n        internal void InvalidateCulture()\n        {\n            _culture = DefaultValueObject;\n        }","sourceCodeStart":1253,"sourceCodeEnd":1289,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpressionBase.cs#L1253-L1289","documentation":"BindingExpressionBase throws this InvalidOperationException when a binding that does not have an explicit ConverterCulture or Source/StringFormat-related culture set must format a value (string formatting or conversion) but the target property has no unambiguous culture. WPF refuses to guess a culture because the inherited CultureInfo (via FrameworkLanguage/FrameworkProperty attached property) can change after load, which would silently produce different formatted strings. The error names the target property so the developer knows which binding to fix.","triggerScenarios":"A Binding with StringFormat or a converter that formats strings, where ConverterCulture is not specified, the binding's Mode involves a transfer that requires culture-sensitive formatting, and the CultureInfo lookup yields an empty/neutral culture (typically in a compiled-XAML/binding path where XmlLanguage is not set). Thrown from BindingExpressionBase.SetupDefaultValueConverter/culture resolution path at BindingExpressionBase.cs:1271.","commonSituations":"Migrating to .NET Framework 4.0+ where the culture-resolution rules became stricter; XAML StringFormat bindings without ConverterCulture; strings like dates/numbers formatted differently than expected and the binding instead throws at runtime; apps with Language attribute omitted on the root element.","solutions":["Set ConverterCulture on the Binding, e.g. ConverterCulture='en-US'.","Set the Language attribute (xml:lang) on the root element of the XAML document, e.g. Language='en-US'.","Set FrameworkElement.LanguageProperty globally (FrameworkElement.LanguageProperty.OverrideMetadata) to a default culture.","If the value need not be culture-formatted, use CultureInfo.InvariantCulture explicitly via ConverterCulture or a converter."],"exampleFix":"<!-- before -->\n<TextBlock Text=\"{Binding Price, StringFormat={}{0:C}}\" />\n\n<!-- after -->\n<TextBlock Text=\"{Binding Price, StringFormat={}{0:C}, ConverterCulture=en-US}\" />","handlingStrategy":"validation","validationCode":"if (binding.ConverterCulture == null && textBlock.Language == null)\n    throw new InvalidOperationException(\"Binding requires explicit ConverterCulture or Language\");","typeGuard":null,"tryCatchPattern":"try { ApplyBinding(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"culture\"))\n{\n    logger.Warn(\"Binding needs explicit culture\", ex);\n}","preventionTips":["Always set xml:lang/Language on XAML root elements","Specify ConverterCulture for any StringFormat binding","Override FrameworkElement.LanguageProperty default app-wide for consistent culture"],"tags":["wpf","data-binding","culture","invalid-operation"],"backgroundTag":"missing-required-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"}