AvaloniaUI/Avalonia · error · InvalidOperationException

Peer instance does not implement {T}.

Error message

Peer instance does not implement {T}.

What it means

GetProvider() asks the automation peer for a provider interface of type T and throws if none is found. There is a latent message bug: `nameof(T)` where T is a generic type parameter returns the literal string "T", so the thrown message is always 'Peer instance does not implement T.' — the actual type is never shown. The real cause is the peer not implementing the requested interface.

Source

Thrown at src/Android/Avalonia.Android/Automation/NodeInfoProvider.cs:42

            VirtualViewId = virtualViewId;

            _peer.PropertyChanged += PeerPropertyChanged;
        }

        protected void InvalidateSelf()
        {
            _owner.InvalidateVirtualView(VirtualViewId);
        }

        protected void InvalidateSelf(int changeTypes)
        {
            _owner.InvalidateVirtualView(VirtualViewId, changeTypes);
        }

        protected virtual void PeerPropertyChanged(object? sender, AutomationPropertyChangedEventArgs e) { }

        public T GetProvider() => _peer.GetProvider<T>() ??
            throw new InvalidOperationException($"Peer instance does not implement {nameof(T)}.");

        public abstract bool PerformNodeAction(int action, Bundle? arguments);

        public abstract void PopulateNodeInfo(AccessibilityNodeInfoCompat nodeInfo);
    }
}

View on GitHub (pinned to 11c5427268)

Solutions

  1. Check whether the peer supports T (peer.GetProvider<T>() != null) before calling, or guard at the caller.
  2. Override GetPattern on the peer to advertise only the patterns it actually implements, and implement those provider interfaces.
  3. Fix the message to print typeof(T).FullName instead of nameof(T) so the missing interface is visible.
  4. If a custom control needs the pattern, implement the matching provider and return it from GetProvider<T>().

Example fix

// before
public T GetProvider() => _peer.GetProvider<T>() ??
    throw new InvalidOperationException($"Peer instance does not implement {nameof(T)}.");

// after (show the actual type and let callers guard)
public T GetProvider() => _peer.GetProvider<T>() ??
    throw new InvalidOperationException(
        $"Peer instance ({_peer.GetType().FullName}) does not implement {typeof(T).FullName}.");
Defensive patterns

Strategy: type-guard

Validate before calling

// ask before demanding
var provider = peer.GetProvider<T>();
if (provider is null) return;

Type guard

static bool Supports<T>(AutomationPeer peer) where T : class => peer.GetProvider<T>() is not null;

Try / catch

try { var p = nodeInfo.GetProvider<T>(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("does not implement"))
{ /* the peer does not expose this pattern; skip */ }

Prevention

When it happens

Trigger: Calling GetProvider<T>() where T is a specific interface (e.g. IValueProvider, IRangeProvider) but the AutomationPeer does not expose that pattern. The provider interface list of the peer does not contain T.

Common situations: Querying a control for an accessibility pattern it does not support (e.g. asking a Button peer for IValueProvider); custom peers that forgot to override GetProvider<T> for a pattern they advertise via GetPattern; mismatched automation peer vs control.

Related errors


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