dotnet/wpf · error · InvalidOperationException
SR.Format(SR.BindingConflict…
Error message
SR.Format(SR.BindingConflict, SourceProperties.StaticSource, _sourceInUse)
What it means
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.
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+.
Example fix
// before
var b = new Binding { Source = obj };
b.SourceReference = StaticSourceRef; // conflict
// after
var b = new Binding { Source = obj }; // single source only Defensive patterns
Strategy: try-catch
Validate before calling
static bool CanSetStaticSource(Binding b) =>
b.Source == null && b.RelativeSource == null && string.IsNullOrEmpty(b.ElementName); Try / catch
try { binding.SourceReference = staticRef; } catch (InvalidOperationException ex) when (ex.Message.Contains("conflict")) { binding = new Binding { SourceReference = staticRef }; } Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- SR.Format(SR.BindingConflict…
- SR.Format(SR.BindingConflict, SourceProperties.Source…
- SR.CollectionView_NameTypeDuplicity
- ArgumentNullException(nameof(value))
- InvalidEnumArgumentException("value", (int) value…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/f8e530d515a74105.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/Binding.cs:317
get { return _ppath; }
set
{
CheckSealed();
_ppath = value;
_attachedPropertiesInPath = -1;
ClearFlag(BindingFlags.PathGeneratedInternally);
if (_ppath != null && _ppath.StartsWithStaticProperty)
{
if (_sourceInUse == SourceProperties.None || _sourceInUse == SourceProperties.StaticSource ||
FrameworkCompatibilityPreferences.TargetsDesktop_V4_0)
{
// net 4.5 breaks static bindings - this is for compat
SourceReference = StaticSourceRef;
}
else
throw new InvalidOperationException(SR.Format(SR.BindingConflict, SourceProperties.StaticSource, _sourceInUse));
}
}
}
/// <summary>
/// This method is used by TypeDescriptor to determine if this property should
/// be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializePath()
{
return _ppath != null && !TestFlag(BindingFlags.PathGeneratedInternally);
}
/// <summary> The XPath path (for XML bindings).</summary>
[DefaultValue(null)]
public string XPath
{View on GitHub (pinned to 81131a70a4)