AvaloniaUI/Avalonia · error · ArgumentException
Binding mode cannot be Default.
Error message
Binding mode cannot be Default.
What it means
BindingExpression's constructor requires a concrete BindingMode. BindingMode.Default is a sentinel meaning 'resolve later from target/property metadata'; it must be resolved to a real mode (OneWay/TwoWay/OneTime/OneWayToSource) before the expression is built. Passing Default through indicates the binding infrastructure skipped resolution.
Source
Thrown at src/Avalonia.Base/Data/Core/BindingExpression.cs:80
object? source,
List<ExpressionNode>? nodes,
object? fallbackValue,
TimeSpan delay = default,
IValueConverter? converter = null,
CultureInfo? converterCulture = null,
object? converterParameter = null,
bool enableDataValidation = false,
BindingMode mode = BindingMode.OneWay,
BindingPriority priority = BindingPriority.LocalValue,
string? stringFormat = null,
object? targetNullValue = null,
AvaloniaProperty? targetProperty = null,
TargetTypeConverter? targetTypeConverter = null,
UpdateSourceTrigger updateSourceTrigger = UpdateSourceTrigger.PropertyChanged)
: base(priority, targetProperty, enableDataValidation)
{
if (mode == BindingMode.Default)
throw new ArgumentException("Binding mode cannot be Default.", nameof(mode));
if (updateSourceTrigger == UpdateSourceTrigger.Default)
throw new ArgumentException("UpdateSourceTrigger cannot be Default.", nameof(updateSourceTrigger));
if (source == AvaloniaProperty.UnsetValue)
source = null;
_source = new(source);
_mode = mode;
_nodes = nodes ?? s_emptyExpressionNodes;
_targetTypeConverter = targetTypeConverter;
_shouldUpdateOneTimeBindingTarget = _mode == BindingMode.OneTime;
if (delay != default ||
converter is not null ||
converterCulture is not null ||
converterParameter is not null ||
fallbackValue != AvaloniaProperty.UnsetValue ||
!string.IsNullOrWhiteSpace(stringFormat) ||View on GitHub (pinned to 11c5427268)
Solutions
- Resolve Default to a concrete mode before constructing the expression: use the target property's default mode or fall back to BindingMode.OneWay.
- If you control the call site, pass an explicit BindingMode.OneWay (or the appropriate mode) instead of relying on Default.
- When building from a Binding object, use Avalonia's Binding.Init / the standard resolution path so Default is converted before reaching BindingExpression.
Example fix
// before var expr = new BindingExpression(..., mode: BindingMode.Default, ...); // after var resolved = mode == BindingMode.Default ? BindingMode.OneWay : mode; var expr = new BindingExpression(..., mode: resolved, ...);
Defensive patterns
Strategy: validation
Validate before calling
// Resolve Default before constructing a BindingExpression.
BindingMode ResolveMode(BindingMode mode) =>
mode == BindingMode.Default ? BindingMode.OneWay : mode;
// usage:
var resolved = ResolveMode(mode);
if (resolved == BindingMode.Default) throw new ArgumentException("mode"); Type guard
static bool IsConcreteMode(BindingMode m) => m != BindingMode.Default;
Prevention
- Never forward BindingMode.Default into BindingExpression; resolve it upstream.
- Default-resolve against the target property metadata when available, else OneWay.
- Unit-test custom binding builders with all five BindingMode values.
When it happens
Trigger: Directly constructing a BindingExpression (or a lower-level binding descriptor) with mode == BindingMode.Default. This normally only happens inside custom binding builders or reflection-based binding setup that forwards an unresolved Default.
Common situations: Writing a custom IBinding/BindingExpression wrapper that forgets to call the mode-resolution step; hand-rolling a compiled-binding pipeline that passes through the enum verbatim; a framework upgrade where Default is no longer auto-resolved at an earlier stage.
Related errors
- UpdateSourceTrigger cannot be Default.
- {this} already has an owner.
- Expected '{open}'.
- StorageItem is not a file
- StorageItem is not a writeable file
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/2c7b318efb81f7b6.
Report an issue: GitHub.