{"record":{"id":"f8e530d515a74105","repo":"dotnet/wpf","slug":"sr-format-sr-bindingconflict-sourceproperties-staticsource","errorCode":null,"errorMessage":"SR.Format(SR.BindingConflict, SourceProperties.StaticSource, _sourceInUse)","messagePattern":"SR\\.Format\\(SR\\.BindingConflict, SourceProperties\\.StaticSource, _sourceInUse\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/Binding.cs","lineNumber":317,"sourceCode":"            get { return _ppath; }\n            set\n            {\n                CheckSealed();\n\n                _ppath = value;\n                _attachedPropertiesInPath = -1;\n                ClearFlag(BindingFlags.PathGeneratedInternally);\n\n                if (_ppath != null && _ppath.StartsWithStaticProperty)\n                {\n                    if (_sourceInUse == SourceProperties.None || _sourceInUse == SourceProperties.StaticSource ||\n                        FrameworkCompatibilityPreferences.TargetsDesktop_V4_0) \n                    {\n                        // net 4.5 breaks static bindings - this is for compat\n                        SourceReference = StaticSourceRef;\n                    }\n                    else\n                        throw new InvalidOperationException(SR.Format(SR.BindingConflict, SourceProperties.StaticSource, _sourceInUse));\n                }\n            }\n        }\n\n        /// <summary>\n        /// This method is used by TypeDescriptor to determine if this property should\n        /// be serialized.\n        /// </summary>\n        [EditorBrowsable(EditorBrowsableState.Never)]\n        public bool ShouldSerializePath()\n        {\n            return _ppath != null && !TestFlag(BindingFlags.PathGeneratedInternally);\n        }\n\n        /// <summary> The XPath path (for XML bindings).</summary>\n        [DefaultValue(null)]\n        public string XPath\n        {","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/Binding.cs#L299-L335","documentation":"A WPF Binding may have only one source: Source, RelativeSource, ElementName, or (static compat path) SourceReference/StaticSource. Setting the static SourceReference (StaticSource) while _sourceInUse already records another source throws InvalidOperationException with SR.BindingConflict naming the conflicting properties.","triggerScenarios":"In the Binding constructor/compat path: assigning a StaticSourceRef-based binding when Source, RelativeSource, or ElementName is already set (except under Desktop_V4_0 compat preferences).","commonSituations":"Constructing bindings in code that copy properties from XAML-defined bindings; shared/deferred Binding instances reused across elements; .NET 4.5 static-binding compat changes mixing with manually set Source.","solutions":["Set exactly one source property; clear others (Source = null, RelativeSource = null, ElementName = null) before assigning another.","Create a fresh Binding instance per element instead of mutating a shared one.","Use the modern StaticResource/MarkupExtension path rather than SourceReference on .NET 4.5+."],"exampleFix":"// before\nvar b = new Binding { Source = obj };\nb.SourceReference = StaticSourceRef; // conflict\n// after\nvar b = new Binding { Source = obj }; // single source only","handlingStrategy":"try-catch","validationCode":"static bool CanSetStaticSource(Binding b) =>\n    b.Source == null && b.RelativeSource == null && string.IsNullOrEmpty(b.ElementName);","typeGuard":null,"tryCatchPattern":"try { binding.SourceReference = staticRef; } catch (InvalidOperationException ex) when (ex.Message.Contains(\"conflict\")) { binding = new Binding { SourceReference = staticRef }; }","preventionTips":["Assign exactly one of Source/RelativeSource/ElementName per Binding.","Never mutate shared Binding instances; create a new one per use.","When building bindings from merged definitions, sanitize source properties first."],"tags":["wpf","binding","data-binding","conflict"],"backgroundTag":"conflicting-config-options","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"}