Element does not exist or it is virtualized; use VirtualizedItem Pattern if it is supported

Viewed 2387

We have a WPF application. Some of our customer are getting a crash, which I am not able to reproduce on my machine.All information that I can get from their machine is below stack trace, which contains only WPF code so I actually cannot pin point what code in my application is causing this issue.

System.Windows.Automation.ElementNotAvailableException: Element does not exist or it is virtualized; use VirtualizedItem Pattern if it is supported.
at System.Windows.Automation.Peers.ItemAutomationPeer.ThrowElementNotAvailableException()
at System.Windows.Automation.Peers.ItemAutomationPeer.GetItemStatusCore()
at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
at System.Windows.Automation.Peers.AutomationPeer.UpdatePeer(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Does anyone facing the same issue? any help is appreciated. This might be related to windows 10 but I am not sure as my machine is also window 10 but I am not getting this error.

6 Answers

Same issue here with both Win7 SP1 (w/ .NET 4.6.1) & Win10 Creators Update (.NET 4.7) systems. Can't really explain the presence of UI automation in the faulty process as no automation clients seem to be running.

Anyway, the problem is related to TreeView controls. Can you also confirm this? For TreeViewItem instances, TreeViewDataItemAutomationPeer objects are created (deriving from ItemAutomationPeer, see callstack) and due to a large number of UIElement.OnIsEnableChanged() calls we end up calling AutomationPeer.InvalidatePeer() that BeginInvoke(s) the faulting delegate to the dispatcher with low priority. It seems that by the time those delegates get processed from the dispatcher queue, the automation tree already changes and the parent / child relationship for one of the peers gets broken. This is why the exception is thrown.

Based on a comment from the framework reference source (scroll up a bit), I'd try the following app.config setting:

Add an entry to the appSettings section of the app config file:

<add key="IsVirtualizingStackPanel_45Compatible" value="true"/>

I have been getting this issue on Windows 10 machines in the past week also. It occurs randomly and very seldom. I have had it occur on 4 x Win10 machines, all Win7 boxes seem fine for now. All users who have had this issue have multiple monitors.

I use a tree control utilising VirtualizingStackPanel, random clicks in the tree cause the exception.

This area of code has been stable for 1 year+ so it is strange that this has started occurring.

Sorry I can't be of more help yet as I am still trying to determine the cause myself.

EDIT: SUCCESS!

I have been working with Microsoft on this one since March and it has finally been resolved. We have been given a private fix and the official fix will be rolled out via Windows Update early 2019.

Even after updating to the May 2018 quality rollup we were still continuing to experience random crashes. Apparently there is some RDP related process that was setting a WinEventHook for EVENTOBJECT_FOCUS which was causing a disconnect between our app and the automation client which eventually resulted in a crash.

This was a real pain to try and replicate and nail down. A big thanks to the MS support and PG team.

We are seeing this issue at my work as well. It's happening on a Win 7 box for us.

Looks like at least one other person has the problem on Win 7 as well: https://social.msdn.microsoft.com/Forums/fr-FR/b7087dc1-3943-4623-bc47-1c1e5021e12f/wpf-application-crashing-after-windows-update-element-does-not-exist-or-it-is-virtualized

We're using .NET 4.6.1. I've been unable to repro on my own machine, but multiple coworkers have been experiencing crashes from this exception.

Here's a sample callstack from a core dump:

PresentationFramework.dll!System.Windows.Automation.Peers.ItemAutomationPeer.ThrowElementNotAvailableException()    Unknown
PresentationFramework.dll!System.Windows.Automation.Peers.ItemAutomationPeer.GetItemStatusCore()    Unknown
PresentationCore.dll!System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree() Unknown
PresentationCore.dll!System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree() Unknown
PresentationCore.dll!System.Windows.Automation.Peers.AutomationPeer.UpdatePeer(object arg)  Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)  Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl()   Unknown
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 954  C#
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 902  C#
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 891    C#
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state)  Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke()   Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue()  Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)  Unknown
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)  Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)   Unknown

Hoping we can find a solution.

Edit: More links to people with this problem:

https://forums.tripwireinteractive.com/forum/killing-floor-2/killing-floor-2-modifications/level-design-ac/2292222-sdk-crash-when-loading-packages-after-win-10-update

Related