AvaloniaUI/Avalonia · error · InvalidOperationException

The member accessor was not subscribed.

Error message

The member accessor was not subscribed.

What it means

PropertyAccessorBase.Unsubscribe throws InvalidOperationException when _listener is null, i.e. Unsubscribe was called on an accessor that was never subscribed (or already unsubscribed). The contract is Subscribe-then-Unsubscribe. (Note: Dispose is safe to call when not subscribed, since it guards on _listener != null.)

Source

Thrown at src/Avalonia.Base/Data/Core/Plugins/PropertyAccessorBase.cs:49

        public void Subscribe(Action<object?> listener)
        {
            _ = listener ?? throw new ArgumentNullException(nameof(listener));

            if (_listener != null)
            {
                throw new InvalidOperationException(
                    "A member accessor can be subscribed to only once.");
            }

            _listener = listener;
            SubscribeCore();
        }

        public void Unsubscribe()
        {
            if (_listener == null)
            {
                throw new InvalidOperationException(
                    "The member accessor was not subscribed.");
            }

            UnsubscribeCore();
            _listener = null;
        }

        /// <summary>
        /// Publishes a value to the listener.
        /// </summary>
        /// <param name="value">The value.</param>
        protected void PublishValue(object? value) => _listener?.Invoke(value);

        /// <summary>
        /// When overridden in a derived class, begins listening to the member.
        /// </summary>
        protected abstract void SubscribeCore();

View on GitHub (pinned to 11c5427268)

Solutions

  1. Ensure Subscribe was called before Unsubscribe.
  2. Guard cleanup with a subscription flag: if (_subscribed) accessor.Unsubscribe().
  3. Prefer Dispose over manual Unsubscribe — Dispose is a no-op when not subscribed.

Example fix

// before
accessor.Unsubscribe(); // throws if not subscribed
// after
if (_subscribed)
{
    accessor.Unsubscribe();
    _subscribed = false;
}
Defensive patterns

Strategy: validation

Validate before calling

// Guard Unsubscribe with the known subscription state:
if (_subscribed) { accessor.Unsubscribe(); _subscribed = false; }

Prevention

When it happens

Trigger: Calling accessor.Unsubscribe() before any Subscribe; calling Unsubscribe twice; manual cleanup ordering bugs that double-unsubscribe.

Common situations: Direct Unsubscribe calls without a prior Subscribe; re-entrant dispose logic; cleanup paths that assume subscription state incorrectly.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/b23d5effbe6d0e58. Report an issue: GitHub.