Reputation: 99
We have a testing automation tool which uses UI Automation API a lot. It occurs that in newest versions of Windows (like Windows 10 21H2, Windows 11) api throws exception System.AccessViolationException
while invoking one of the methods of AutomationElement class.
Here is our code:
AutomationElement uiaElement;
....
var cr = new CacheRequest
{
AutomationElementMode = AutomationElementMode.None,
TreeScope = TreeScope.Element,
TreeFilter = Automation.RawViewCondition
};
cr.Add(InvokePattern.Pattern);
cr.Add(TogglePattern.Pattern);
cr.Add(RangeValuePattern.Pattern);
cr.Add(ValuePattern.Pattern);
cr.Add(ItemContainerPattern.Pattern);
cr.Add(VirtualizedItemPattern.Pattern);
var cachedElement = uiaElement.GetUpdatedCache(capabilitiesCacheRequest);
Method GetUpdatedCache
comes from AutomationElement
(UIAutomationClient.dll
) and invokes method from UIAutomationCore.dll
called RawUiaHPatternObjectFromVariant
- this method throws exception and I am not sure how to proceed given that everything works fine on earlier versions of Windows.
For now we just tried handling this exception - of course it is not acceptable in a long run.
One thing to mention is that both newever versions of Windows on which we tested this are in preview/beta state. Is this possible that certain API are "disabled" in such versions (of course they maybe also be broken), does anyone has experience with such situations? I am asking about both - solving System.AccessViolationException in general and not properly working API in beta/preview releases.
Upvotes: 1
Views: 729
Reputation: 441
You might need to turn off completely Windows UAC and Defender/SmartScreen, and add manifest to exe to run tests under elevated account.
Upvotes: 1