MSBuildStructuredLog icon indicating copy to clipboard operation
MSBuildStructuredLog copied to clipboard

WPF: ArgumentNullException in VisualTreeUtils.AsNonNullVisual

Open kant2002 opened this issue 3 years ago • 11 comments

System.ArgumentNullException: Value cannot be null.
Parameter name: element
   at MS.Internal.Media.VisualTreeUtils.AsNonNullVisual(DependencyObject element, Visual& visual, Visual3D& visual3D)
   at System.Windows.Media.VisualTreeHelper.GetParent(DependencyObject reference)
   at System.Windows.Controls.VirtualizingStackPanel.FindScrollOffset(Visual v)
   at System.Windows.Controls.VirtualizingStackPanel.OnAnchorOperation(Boolean isAnchorOperationPending)
   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)

You have the latest version: 2.1.627

It maybe issue with WPF

kant2002 avatar Mar 14 '22 09:03 kant2002

does this happen for any binlog or for a specific one? could you email me the problematic binlog? to my first name dot last name at microsoft. Did you try on another computer? did you try on https://live.msbuildlog.com

KirillOsenkov avatar Mar 14 '22 17:03 KirillOsenkov

I did try on different computer. No luck. Forget about live viewing. Will check tomorrow. Also, observation. I open file, it start scrolling and probably expanding nodes. Then exception, and then I was able to browse and seems to be no issues with content.

kant2002 avatar Mar 14 '22 17:03 kant2002

@sambent anything jump at you from the stack above?

KirillOsenkov avatar Mar 14 '22 17:03 KirillOsenkov

@kant2002 can you open your PresentationFramework.dll in ILSpy and tell me the version of the file mentioned in the attributes? should be something like 4455 or 4470.

KirillOsenkov avatar Mar 14 '22 17:03 KirillOsenkov

[assembly: AssemblyInformationalVersion("4.8.4470.0")]

kant2002 avatar Mar 14 '22 17:03 kant2002

Also I experience very similar, but slightly different exception with same file, and same conditions

System.ArgumentNullException: Value cannot be null.
Parameter name: element
   at MS.Internal.Media.VisualTreeUtils.AsNonNullVisual(DependencyObject element, Visual& visual, Visual3D& visual3D)
   at System.Windows.Media.VisualTreeHelper.GetParent(DependencyObject reference)
   at System.Windows.Controls.VirtualizingStackPanel.FindScrollOffset(Visual v)
   at System.Windows.Controls.VirtualizingStackPanel.OnAnchorOperation(Boolean isAnchorOperationPending)
   at System.Windows.Controls.VirtualizingStackPanel.SetAnchorInformation(Boolean isHorizontalOffset)
   at System.Windows.Controls.VirtualizingStackPanel.<>c__DisplayClass94_0.<InitializeViewport>b__0()
   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)

That exception happens when I click on the tree, when it is expanding and before tree finish it's expansion.

kant2002 avatar Mar 14 '22 18:03 kant2002

I haven't seen this before. OnAnchorOperation calls FindScrollOffest twice - once for the (deepest) TreeViewItem at the top of the viewport before the scroll, and once for the topmost element after the scroll. One of these is null, but neither is supposed to be. The TreeView layout is getting confused somehow, but I'd need more evidence to figure out how. A callstack, and even a crash dump, is not enough - as usual the problem is likely to have occurred long before the crash. In order of preference: A reliable repro, a time-travel trace, or an STF trace (with matching crash dump).

SamBent avatar Mar 14 '22 18:03 SamBent

@kant2002 if you go to Start Page in the binlog viewer, and disable tree view virtualization, I expect the problems to go away. Could you confirm it?

Also, could you send me that binlog file if possible?

What is the screen DPI of that monitor? More than 100%? How many monitors do you have and what’s the screen resolution?

KirillOsenkov avatar Mar 14 '22 22:03 KirillOsenkov

@kant2002 if you go to Start Page in the binlog viewer, and disable tree view virtualization, I expect the problems to go away. Could you confirm it?

@KirillOsenkov I confirm that issue goes away.

Also, could you send me that binlog file if possible?

Unless your email has one L instead of two, or youg github handle does not reflect your name, you should have email with file attached.

What is the screen DPI of that monitor? More than 100%? How many monitors do you have and what’s the screen resolution?

One external monitor attached to laptop. DPI = 100% (I assume this is Scale And Layout in the Home -> Display section in the System Settings), resolution 1920x1080

kant2002 avatar Mar 15 '22 04:03 kant2002

I got the binlog, thanks! Unfortunately it works just fine on my machine. I'll try a few other things too.

Meanwhile, if you have time, could you please try to record scrollTrace.stf as described here: https://github.com/KirillOsenkov/MSBuildStructuredLog/issues/21#issuecomment-514701904

We had a couple similar issues: https://github.com/KirillOsenkov/MSBuildStructuredLog/issues/407 https://github.com/KirillOsenkov/MSBuildStructuredLog/issues/21

KirillOsenkov avatar Mar 15 '22 05:03 KirillOsenkov

Send STF file to same location. Anything else what I can do?

kant2002 avatar Mar 15 '22 05:03 kant2002