{"record":{"id":"bd3b5be0fa7ee29f","repo":"AvaloniaUI/Avalonia","slug":"bindingexpression-has-not-been-started","errorCode":null,"errorMessage":"BindingExpression has not been started.","messagePattern":"BindingExpression has not been started\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Data/Core/UntypedBindingExpressionBase.cs","lineNumber":128,"sourceCode":"        _frame = null;\n        sink.OnCompleted(this);\n        frame?.OnEntryDisposed(this);\n    }\n\n    /// <summary>\n    /// Gets the current value of the binding expression.\n    /// </summary>\n    /// <returns>\n    /// The current value or <see cref=\"AvaloniaProperty.UnsetValue\"/> if the binding was unable\n    /// to read a value.\n    /// </returns>\n    /// <exception cref=\"InvalidOperationException\">\n    /// The binding expression has not been started.\n    /// </exception>\n    public object? GetValue()\n    {\n        if (!IsRunning)\n            throw new InvalidOperationException(\"BindingExpression has not been started.\");\n        return _value;\n    }\n\n    /// <summary>\n    /// Gets the current value of the binding expression or the default value for the target property.\n    /// </summary>\n    /// <returns>\n    /// The current value or the target property default.\n    /// </returns>\n    public object? GetValueOrDefault()\n    {\n        var result = GetValue();\n        if (result == AvaloniaProperty.UnsetValue)\n            result = GetCachedDefaultValue();\n        return result;\n    }\n\n    /// <summary>","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Data/Core/UntypedBindingExpressionBase.cs#L110-L146","documentation":"GetValue() on an UntypedBindingExpressionBase returns the cached current value, but only after the expression has been started (attached to a target via the ValueStore). If IsRunning is false the binding is not yet wired up, so there is no meaningful value, and the method throws InvalidOperationException.","triggerScenarios":"Calling `expression.GetValue()` on a binding expression that was constructed but never attached to an AvaloniaObject target (no Start/Attach was invoked). Reading the value of an expression before the ValueStore has started it.","commonSituations":"Unit tests that create a binding expression and immediately read its value without applying it to a control. Calling GetValue() on a freshly instantiated expression returned from IBinding.CreateInstance before it is attached.","solutions":["Apply the binding to a target AvaloniaObject (e.g. via `control.Bind(property, binding)`) so the expression starts before you read it.","Use GetValueOrDefault() if you only need the current value or the property default and cannot guarantee the expression started.","In tests, drive the binding through a real AvaloniaObject/ValueStore rather than probing a detached expression."],"exampleFix":"// before:\nvar expr = myBinding.CreateInstance(target, prop, anchor);\nvar val = expr.GetValue(); // throws\n\n// after:\ntarget.Bind(prop, myBinding);\n// let the value store start the expression, then read the property:\nvar val = target.GetValue(prop);","handlingStrategy":"validation","validationCode":"if (!expr.IsRunning)\n    throw new InvalidOperationException(\"Start the expression before reading.\");\nvar v = expr.GetValue();","typeGuard":"static bool HasStarted(UntypedBindingExpressionBase e) => e.IsRunning;","tryCatchPattern":"try { var v = expr.GetValue(); }\ncatch (InvalidOperationException) when (!expr.IsRunning)\n{\n    // expression not attached; read target property default instead\n}","preventionTips":["Apply bindings to a target so the ValueStore starts them.","Prefer GetValueOrDefault() when start state is uncertain.","In tests, drive bindings through a real AvaloniaObject."],"tags":["bindings","bindingexpression","invalidoperation","valuestore"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}