From f8a1f2e2aa1aca96f5b0bfb5c3e31ee245efcdac Mon Sep 17 00:00:00 2001 From: SunnyDesignor <50539661+SunnyDesignor@users.noreply.github.com> Date: Mon, 16 Feb 2026 17:18:07 +0800 Subject: [PATCH] Fix unexpected crashes during accessibility actions. (#20687) --- .../Avalonia.Android/AvaloniaAccessHelper.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Android/Avalonia.Android/AvaloniaAccessHelper.cs b/src/Android/Avalonia.Android/AvaloniaAccessHelper.cs index ac92aafc29..ca06998dbc 100644 --- a/src/Android/Avalonia.Android/AvaloniaAccessHelper.cs +++ b/src/Android/Avalonia.Android/AvaloniaAccessHelper.cs @@ -135,10 +135,30 @@ namespace Avalonia.Android protected override bool OnPerformActionForVirtualView(int virtualViewId, int action, Bundle? arguments) { return (GetNodeInfoProvidersFromVirtualViewId(virtualViewId) ?? []) - .Select(x => x.PerformNodeAction(action, arguments)) + .Select(x => TryPerformNodeAction(x, action, arguments)) .Aggregate(false, (a, b) => a | b); } + private static bool TryPerformNodeAction(INodeInfoProvider nodeInfoProvider, int action, Bundle? arguments) + { + try + { + return nodeInfoProvider.PerformNodeAction(action, arguments); + } + catch (ElementNotEnabledException) + { + return false; + } + catch (InvalidOperationException) + { + return false; + } + catch (NotSupportedException) + { + return false; + } + } + protected override void OnPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat? nodeInfo) { if (nodeInfo is null || !_peers.TryGetValue(virtualViewId, out AutomationPeer? peer))