{"record":{"id":"30ffb842ac6189d0","repo":"AvaloniaUI/Avalonia","slug":"peer-instance-does-not-implement-t","errorCode":null,"errorMessage":"Peer instance does not implement {T}.","messagePattern":"Peer instance does not implement (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Android/Avalonia.Android/Automation/NodeInfoProvider.cs","lineNumber":42,"sourceCode":"            VirtualViewId = virtualViewId;\n\n            _peer.PropertyChanged += PeerPropertyChanged;\n        }\n\n        protected void InvalidateSelf()\n        {\n            _owner.InvalidateVirtualView(VirtualViewId);\n        }\n\n        protected void InvalidateSelf(int changeTypes)\n        {\n            _owner.InvalidateVirtualView(VirtualViewId, changeTypes);\n        }\n\n        protected virtual void PeerPropertyChanged(object? sender, AutomationPropertyChangedEventArgs e) { }\n\n        public T GetProvider() => _peer.GetProvider<T>() ??\n            throw new InvalidOperationException($\"Peer instance does not implement {nameof(T)}.\");\n\n        public abstract bool PerformNodeAction(int action, Bundle? arguments);\n\n        public abstract void PopulateNodeInfo(AccessibilityNodeInfoCompat nodeInfo);\n    }\n}\n","sourceCodeStart":24,"sourceCodeEnd":49,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Android/Avalonia.Android/Automation/NodeInfoProvider.cs#L24-L49","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check whether the peer supports T (peer.GetProvider<T>() != null) before calling, or guard at the caller.","Override GetPattern on the peer to advertise only the patterns it actually implements, and implement those provider interfaces.","Fix the message to print typeof(T).FullName instead of nameof(T) so the missing interface is visible.","If a custom control needs the pattern, implement the matching provider and return it from GetProvider<T>()."],"exampleFix":"// before\npublic T GetProvider() => _peer.GetProvider<T>() ??\n    throw new InvalidOperationException($\"Peer instance does not implement {nameof(T)}.\");\n\n// after (show the actual type and let callers guard)\npublic T GetProvider() => _peer.GetProvider<T>() ??\n    throw new InvalidOperationException(\n        $\"Peer instance ({_peer.GetType().FullName}) does not implement {typeof(T).FullName}.\");","handlingStrategy":"type-guard","validationCode":"// ask before demanding\nvar provider = peer.GetProvider<T>();\nif (provider is null) return;","typeGuard":"static bool Supports<T>(AutomationPeer peer) where T : class => peer.GetProvider<T>() is not null;","tryCatchPattern":"try { var p = nodeInfo.GetProvider<T>(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"does not implement\"))\n{ /* the peer does not expose this pattern; skip */ }","preventionTips":["Check GetProvider<T>() for null before calling GetProvider().","Advertise only supported patterns in GetPattern.","Print typeof(T).FullName in the message (nameof(T) returns literal 'T')."],"tags":["android","accessibility","automation-peer","a11y","generic-type","message-bug"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}