I am getting much closer to figuring this out and primarily posting to share my results.
What I am seeing is that a couple calls to User32.FindWindow (on the same window) will screw up a calls to UI Automation core methods such as FindAllBuildCache().
Does anyone know if there is a proper way to dispose of the handles you get back from a PInvoke FindWindow call?
BrendanMcKless,
Thanks for pointing that out. That is good information to have.
Now I am 99% sure that the issue I encountered was due to using the UIAutomationCore at the same time as the AutomationClient. The Core I am using by having a tlbimp build step to create a managed assembly from the Core DLL. I get better performance using the Core, and also get a pattern called IUIAutomationLegacyIAccessiblePattern, which enables me to get the cell contents from an Infragistics Ultragrid. I noticed yesterday that even if I don’t use the AutomationClient, my test begins to encounter problems as soon as the assembly is loaded:
I see this in the output window when I create an instance of a class with AutomationClient imports:
The problem could be the Accessibility.dll because I am using IUIAutomationLegacyIAccessiblePattern, but that DLL is being loaded as a dependency of UIAutomationClientsideProviders.dll anyways so….
I’ll update my post if the solution doesn’t turn out to be correct (I have a significant amount of rework to do before I can be 100% sure).
Added a while later:
The problem was definitely using the UI Automation Core along with the managed client side UI Automation stuff. What a pain!