Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NRE in Automation Peers #122

Closed
clairernovotny opened this issue Dec 7, 2018 · 12 comments · Fixed by #7115
Closed

NRE in Automation Peers #122

clairernovotny opened this issue Dec 7, 2018 · 12 comments · Fixed by #7115
Labels
Bug Product bug (most likely) needs-watson-data Needs data from telemetry

Comments

@clairernovotny
Copy link
Member

clairernovotny commented Dec 7, 2018

.NET Core 3 preview 1

This is from my telemetry and resulted in an app crash.

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Automation.Peers.ItemAutomationPeer.GetNameCore()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.ContextLayoutManager.fireAutomationEvents()
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(object arg)
   at System.Windows.Media.MediaContext+InvokeOnRenderCallback.DoWork()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.AnimatedRenderMessageHandler(object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, object args, int numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, Delegate callback, object args, int numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, object state)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, object args, int numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, Delegate callback, object args, int numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, object args, int numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(ref MSG msg)
   at System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(ref MSG msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at PackageExplorer.App.Main()
@rladuca rladuca added the Bug Product bug (most likely) label Dec 7, 2018
@rladuca rladuca added this to the 3.0 milestone Dec 7, 2018
@rladuca
Copy link
Member

rladuca commented Dec 7, 2018

@miguep Will this be part of the remaining diff of desktop framework 4.8 to .NET Core 3?

@miguep miguep modified the milestones: 3.0, Future Dec 8, 2018
@miguep
Copy link
Contributor

miguep commented Dec 8, 2018

@rladuca it is not part of that work

@clairernovotny
Copy link
Member Author

clairernovotny commented Feb 26, 2019

I'm seeing a lot of these happen still, any reason this can't be looked at for 3.0?

Stack from earlier today:

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Automation.Peers.ItemAutomationPeer.GetNameCore()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   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, int numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, Delegate callback, object args, int numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, object state)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, object args, int numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, Delegate callback, object args, int numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, object args, int numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam)

@miguep
Copy link
Contributor

miguep commented Apr 1, 2019

We've observed this failure in .NET Framework as well and do not believe this is new to Core.

The WPF team's focus currently is on ensuring functional and performance parity between WPF in .NET Core and .NET Framework, once we meet that goal we can start looking into fixing some of these bugs

@weltkante
Copy link

Maybe quantify what "a lot" means. If the exception is rare in Desktop Framework and common in Core Framework that would still be a regression (in my opinion).

@vatsan-madhavan vatsan-madhavan added the needs-watson-data Needs data from telemetry label May 29, 2019
@MarkWatts12
Copy link

Seeing the same issue here. WPF (Framework 4.8 and 4.7.2) Same stack trace more or less. Can't find the culprit.

@eriove
Copy link

eriove commented Aug 24, 2020

I suddenly started to get this every 2 seconds instead of once every other day of using the program. I turned on Framework source code debugging and the code fails on else if (item != null) in ItemAutomationPeer.GetNameCore()

image

Yes, that's a null reference exception on the line that checks if an object is null.

Not much else can be seen in the debugger. Here are the local variables
image

Most notably item is a MS.Internal.NamedObject with the value "{DependencyProperty.UnsetValue}".

I really can't understand why the code throws at that line. I suspect the symbols, binary and source are out of sync.

@KirillOsenkov
Copy link
Member

The nullref is because the ItemsControlAutomationPeer is null:

image

@KirillOsenkov
Copy link
Member

This is during scrolling of a virtualized tree view when the peer tree view item has been scrolled away and there's no container matching the peer item.

Here's a more relevant stack where ContainerFromItem returns null for an item, which propagates all the way down to ItemsControlAutomationPeer property which returns null and throws.

 PresentationFrameworkItemContainerGenerator.ContainerFromItem Line 605
 PresentationFrameworkItemAutomationPeer.GetWrapper Line 104
 PresentationFrameworkItemAutomationPeer.GetWrapperPeer Line 114
 PresentationFrameworkTreeViewDataItemAutomationPeer.GetWrapperPeer Line 83
 PresentationFrameworkTreeViewDataItemAutomationPeer.GetItemsControlAutomationPeer Line 122
 PresentationFrameworkItemAutomationPeer.get_ItemsControlAutomationPeer Line 693
 PresentationFrameworkItemAutomationPeer.GetWrapper Line 92
 PresentationFrameworkItemAutomationPeer.GetWrapperPeer Line 114
 PresentationFrameworkTreeViewDataItemAutomationPeer.GetWrapperPeer Line 83
 PresentationFrameworkTreeViewItemAutomationPeer.iterate Line 123
 PresentationFrameworkTreeViewItemAutomationPeer.iterate Line 145
 PresentationFrameworkTreeViewItemAutomationPeer.iterate Line 145
 PresentationFrameworkTreeViewItemAutomationPeer.iterate Line 145
 PresentationFrameworkTreeViewItemAutomationPeer.GetChildrenCore Line 68
 PresentationCoreAutomationPeer.EnsureChildren Line 1402
 PresentationCoreAutomationPeer.ForceEnsureChildren Line 1422
 PresentationFrameworkItemAutomationPeer.GetChildrenCore Line 203
 PresentationCoreAutomationPeer.EnsureChildren Line 1402
 PresentationCoreAutomationPeer.UpdateChildrenInternal Line 1815
 PresentationCoreAutomationPeer.UpdateChildren Line 1927
 PresentationCoreAutomationPeer.UpdateSubtree Line 2017
 PresentationCoreAutomationPeer.UpdateSubtree Line 2021
 PresentationCoreAutomationPeer.UpdateSubtree Line 2021
 PresentationCoreAutomationPeer.UpdateSubtree Line 2021
 PresentationCoreAutomationPeer.UpdateSubtree Line 2021
 PresentationCoreAutomationPeer.UpdateSubtree Line 2021
 PresentationCoreAutomationPeer.FireAutomationEvents Line 1784
 PresentationCoreContextLayoutManager.fireAutomationEvents Line 728
 PresentationCoreContextLayoutManager.UpdateLayout Line 425

@KirillOsenkov
Copy link
Member

This line is clearly missing a null check for ItemsControlAutomationPeer:

using (RecyclableWrapper recyclableWrapper = ItemsControlAutomationPeer.GetRecyclableWrapperPeer(item))

@KirillOsenkov
Copy link
Member

To clarify: the peer that has its ItemsControlAutomationPeer null is:
System.Windows.Automation.Peers.TreeViewDataItemAutomationPeer

KirillOsenkov added a commit to KirillOsenkov/wpf that referenced this issue Sep 24, 2022
…Core()

For virtualized tree views it can happen that we are calling GetNameCore() on an item that has been scrolled out of view and doesn't have an associated container. ItemContainerGenerator.GetContainerFromItem() returns null, and so ItemsControlAutomationPeer ends up being null as well.

We're still going to retrieve the name from the item.ToString(), so it's much better than crashing here and aborting the entire layout pass.
@KirillOsenkov
Copy link
Member

This is a more impactful issue in WPF that impacts a lot of customers. Simple web search for ItemAutomationPeer.GetNameCore() will result in a lot of hits and a lot of people seeing this.

We need to service .NET Framework 4.8 with this fix after testing.

dipeshmsft pushed a commit that referenced this issue Dec 14, 2022
…#7115)

For virtualized tree views it can happen that we are calling GetNameCore() on an item that has been scrolled out of view and doesn't have an associated container. ItemContainerGenerator.GetContainerFromItem() returns null, and so ItemsControlAutomationPeer ends up being null as well.

We're still going to retrieve the name from the item.ToString(), so it's much better than crashing here and aborting the entire layout pass.
@ghost ghost removed the 🚧 work in progress label Dec 14, 2022
@ghost ghost removed this from the Future milestone Dec 14, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jan 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Product bug (most likely) needs-watson-data Needs data from telemetry
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants