I am experiencing frequent Powershell crashes with extensive use of UIAutomation and try-catch blocks. Not sure if this is specific to UIAutomation but I sorely need some advice how to workaround this problem.
Periodically, I will get popup dialog box that Powershell has stopped working and the script will freeze. (Dismissing the dialog will exit the script.) Windows Application Event log will show WER (Windows Error Reporting) details with a reference to a local
Report.wer file. The contents of the file describe crash because some item (not specified) is not found with "Windows.Automation.ElementNotAvailable" error.
However running the script again crashes in another location in the script (with same kind of error), successfully getting past the place where the first crash was said to not find some unknown item.
Because I am dealing with an application where one or more dialogs will show up under certain circumstances in an unknown order, I use try-catch blocks. They seem to work, but I encounter these crashes seemingly only in a script when using several independent
Because the crash can occur in more than one place in the same script, I consider it
might be a resource or memory issue, so I have increased the memory used by PowerShell, but that did not help.
What to do? Any advice?
(Is there a way to get the error report to indicate which item was not found?)
============ Example of Report.wer file: =================
UI=powershell has stopped working
UI=Windows can check online for a solution to the problem.
UI=Check online for a solution and close the program
UI=Check online for a solution later and close the program
UI=Close the program
=============== Example of Event log message: ============
Fault bucket 50022624, type 21
Event Name: PowerShell
Response: Not available
Cab Id: 0
These files may be available here:
Rechecking for solution: 0
Report Id: 92f53781-091b-11e4-bd2a-586d8f50ad6d
Report Status: 0
Thanks for any advice or help.
Jul 11, 2014 at 7:14 PM
I believe I have fixed this or a very similar issue - right now I can't say whether it's published or not yet.
Initially the issue I faced grew from the wizard cmdlets, specifically the Invoke-UiaWizard cmdlet, but was not limited to these cmdlets.
The issue, however, didn't throw a dialog, it threw an internal MS UI Automation exception that could suddenly spoil the script execution.
Fortunately, I have a keyboard at work with "run a process" button (a Microsoft's keyboard with the Calc button that runs calc.exe). I have even bought the same for home. :)
If you run something like (I forgot the exact script I tested with :( ) Get-UiaWindow -n calc* -Seconds 300 and run and close some windows called calc* (I used my fingers and the MS keyboard), it often throws an internal exception, and go out of the waiting
for a window.
Probably, it was fixed after I uploaded the last binaries - I'll build today a version and upload it as non-public beta to allow you to run the latest binaries in the hope that the issue could be fixed.
Jul 12, 2014 at 9:50 AM
I uploaded the current binaries as
0.8.7 Beta 3
Just to learn whether the problem is fixed or still in the code.
Unfortunately, when I introduced new logging, calls to cmdlets and object model were added to the logging, but many failures like "control not found" weren't. I'll add failure output to the log ~next week.
Thanks apetrovsky for the quick response and the build.
When I attempt to run with this new 0.8.7 Beta 3, I get "Could not load file or assembly " messages:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\Tools\PowerShell> ipmo ($env:USERPROFILE + "\Documents\WindowsPowerShell\M
Import-Module : Could not load file or assembly 'file:///C:\Users\username\
Documents\WindowsPowerShell\Modules\UIAutomation\UIAutomation.dll' or one of it
s dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515
At line:1 char:5
- ipmo <<<< ($env:USERPROFILE + "\Documents\WindowsPowerShell\Modules\UIAutoma
- CategoryInfo : NotSpecified: (:) [Import-Module], FileLoadExcep
- FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell
This of course worked with previous build (0.8.7 Beta 2).
Perhaps, is there some version dependency?
Jul 14, 2014 at 6:58 PM
Have you unchecked the Unblock button in the file Properties dialog of the archive you have downloaded?
It's default security feature of contemporary Windows systems, to block files users downloaded from the Internet.
Just to unblock the archive, unpack and the contents of the archive is also unblocked.
Thanks apetrovsky, for the reminder. Yes, the download security feature stopped the loading of the module. Once I "unblocked" the files, I can load the module.
I am running the automation now to see the state of things. So far I have not encountered the original error condition, but I need to do more testing. I will comment here when I have done more testing.
Thanks for the build.
I do not see the worst of these errors, "Windows.Automation.ElementNotAvailable ", in the new build
I still get errors, but it appears that the application being tested also has a memory leak or some other instabilities. Therefore it is hard to pin down where or what is going on, and where the root cause is. But it seems UIAutomation is more stable.