2

A little background...

I am developing a UI automation app that randomly interacts with controls on our UI. Both the app and the UI being automated are WPF applications. I am using the UI Automation accessibility framework. Occasionally I get an ElementNotAvailableException in my app which I catch and handle. When profiling our UI using ANTS 7, I have noticed these exceptions are showing up on the Gen 2 garbage heap. The new instances of the exception match the number of times I caught the exception in my app.

I have looked at the GCRoot using WinDBG, the UIAutomation pages, and I have not found a clear explanation as to why a caught exception is appearing in the app being automated. The objects are not released when the UI is being automated and even remain when I close my automation app.

Any ideas?

1 Answers1

1

Without knowing exactly how it is implemented, we can know that in order for UI automation to do what it does it needs to do:

  • instrumentation, and
  • interprocess communication

The instrumentation part consists of infrastructure that is literally compiled into all of the classes in the UI framework or added to the framework, hooked if you will. It "infects" the host application and runs a mini-application inside it.

The interprocess communication part is needed to pass non-graphical information between the client and the host such as the actual contents of a text box. This sounds simple but invokes literally injecting and exchanging types and values between the two processes.

Now when you combine these two things, an exception could be exchanged as part of interprocess communication and that exception could be held as a reference by the mini-application that is the automation framework, and you have a speculative explanation for how it could happen.

In your case, if you are curious enough, or motivated enough (perhaps by a bug), you could keep drilling into this issue with various tools. You have the debugger, ILSpy, black-box experiments, heap tools, etc. It's up to you how far you need to go.

Rick Sladkey
  • 33,988
  • 6
  • 71
  • 95
  • Thanks for the response. My suspicion was the something with the communication between the automation app and the UI, causing the exception to appear in the UI being automated by not disposed. I will look further with some more debugging tools. – Raffledoocious May 17 '11 at 15:24