CrossThreadMessagingException, on doing AutomationUtilities.FindElementsByName(...)

Jan 19, 2009 at 3:37 PM
HI

I am running an NUNIT test to do UI Automation of my WPF app, in VS2008.
I set a breakpoint after launching my WPF app main window to start doing UIA.

I then do the following in the VS2008 Immediate Window (Ctrl + D, I)

System.Windows.Automation.AutomationElement partYearTextBox = AutomationUtilities.FindElementsByName(AutomationElement.RootElement, "PART_Year")[0];

And get the exception below ...

I am not sure, but I think this might be a bug somewhere in VS2008.

Here's the exception:

Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException crossed a native/managed boundary
  Message="An exception 'Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException' occurred"
  Source="Microsoft.VisualStudio.Debugger.Runtime"
  StackTrace:
       bei Microsoft.VisualStudio.Debugger.Runtime.Main.ThrowCrossThreadMessageException(String formatString)
       bei Accessibility.IAccessible.get_accName(Object varChild)
       bei MS.Internal.AutomationProxies.ProxySimple.GetAccessibleName(Int32 item)
       bei MS.Internal.AutomationProxies.ProxyHwnd.GetElementProperty(AutomationProperty idProp)
       bei MS.Internal.AutomationProxies.ProxySimple.System.Windows.Automation.Provider.IRawElementProviderSimple.GetPropertyValue(Int32 propertyId)
  InnerException:

Thanks,
Paul
Developer
Jan 19, 2009 at 10:24 PM
Hi Paul,

Is this issue specific to code run under the immediate window, or is that just a particularly simple repro? Would you be able to get the inner exception on that? 

By the way, consider searching against automation ID's rather than name, as a general practice(not directly pertinent to this issue, however).

Thanks,

Peter