2

A call to Invoke() method(from System.Windows.Automation.InvokePattern) fails as soon as the system is locked. This behavior is seen after migrating our project to .NET 4.5.2. Whereas in .NET 4.0 the call used to work even when system was locked.

The dll used is UIAutomationClient.dll, v4.0.0.0.

The exception I get is:

System.InvalidOperationException was unhandled by user code Message=Operation is not valid due to the current state of the object.

I know GUI testing with UIA usually needs the system to be unlocked.Since this call was working when the system is locked in .NET 4.0, I would like to have the same behavior after migration.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
SPK
  • 21
  • 2
  • Are you sure it has anything to do with .NET version? There's nothing explicitly throwing `InvalidOperationException` in the relevant code, so it's likely coming from the COM Automation API directly. And according to documentation, `The element does not support the InvokePattern control pattern or is hidden or blocked.`, so what you're doing is definitely not supported, and never was. – Luaan Sep 03 '15 at 12:03

2 Answers2

1

According to the documentation, InvalidOperationException is thrown when

The element does not support the InvokePattern control pattern or is hidden or blocked.

This goes all the way back to .NET 3.0, and isn't really handled by the .NET side anyway (it's in the underlying COM APIs), so it's quite unlikely this has anything to do with .NET version.

Luaan
  • 62,244
  • 7
  • 97
  • 116
0

I would not recommend doing anything with GUI when the system is locked. In such case GUI context is lost. So you're even not able to send keyboard or mouse event programmatically at all. But you may keep Remote Desktop (or VNC server software) session in window mode, non-minimized, with lost focus. GUI context is alive, you're able to work on local machine in another window in parallel with GUI automation script on the remote PC.

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78