{"record":{"id":"2c7b318efb81f7b6","repo":"AvaloniaUI/Avalonia","slug":"binding-mode-cannot-be-default","errorCode":null,"errorMessage":"Binding mode cannot be Default.","messagePattern":"Binding mode cannot be Default\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Data/Core/BindingExpression.cs","lineNumber":80,"sourceCode":"        object? source,\n        List<ExpressionNode>? nodes,\n        object? fallbackValue,\n        TimeSpan delay = default,\n        IValueConverter? converter = null,\n        CultureInfo? converterCulture = null,\n        object? converterParameter = null,\n        bool enableDataValidation = false,\n        BindingMode mode = BindingMode.OneWay,\n        BindingPriority priority = BindingPriority.LocalValue,\n        string? stringFormat = null,\n        object? targetNullValue = null,\n        AvaloniaProperty? targetProperty = null,\n        TargetTypeConverter? targetTypeConverter = null,\n        UpdateSourceTrigger updateSourceTrigger = UpdateSourceTrigger.PropertyChanged)\n            : base(priority, targetProperty, enableDataValidation)\n    {\n        if (mode == BindingMode.Default)\n            throw new ArgumentException(\"Binding mode cannot be Default.\", nameof(mode));\n        if (updateSourceTrigger == UpdateSourceTrigger.Default)\n            throw new ArgumentException(\"UpdateSourceTrigger cannot be Default.\", nameof(updateSourceTrigger));\n\n        if (source == AvaloniaProperty.UnsetValue)\n            source = null;\n\n        _source = new(source);\n        _mode = mode;\n        _nodes = nodes ?? s_emptyExpressionNodes;\n        _targetTypeConverter = targetTypeConverter;\n        _shouldUpdateOneTimeBindingTarget = _mode == BindingMode.OneTime;\n\n        if (delay != default ||\n            converter is not null ||\n            converterCulture is not null ||\n            converterParameter is not null ||\n            fallbackValue != AvaloniaProperty.UnsetValue ||\n            !string.IsNullOrWhiteSpace(stringFormat) ||","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Data/Core/BindingExpression.cs#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar expr = new BindingExpression(..., mode: BindingMode.Default, ...);\n// after\nvar resolved = mode == BindingMode.Default ? BindingMode.OneWay : mode;\nvar expr = new BindingExpression(..., mode: resolved, ...);","handlingStrategy":"validation","validationCode":"// Resolve Default before constructing a BindingExpression.\nBindingMode ResolveMode(BindingMode mode) =>\n    mode == BindingMode.Default ? BindingMode.OneWay : mode;\n\n// usage:\nvar resolved = ResolveMode(mode);\nif (resolved == BindingMode.Default) throw new ArgumentException(\"mode\");","typeGuard":"static bool IsConcreteMode(BindingMode m) => m != BindingMode.Default;","tryCatchPattern":null,"preventionTips":["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."],"tags":["data-binding","binding-mode","validation","internal-api"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}