dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.05k stars 1.17k forks source link

Tooltip throws ArgumentNullException #7002

Closed JNaumann86 closed 1 year ago

JNaumann86 commented 2 years ago

Bug looks similar to this bug, which has been already fixed: https://github.com/dotnet/wpf/issues/6319 But bug still exists by doing different repro.

Actual behavior: App crashes with the following exception:

System.ArgumentNullException: Value cannot be null. (Parameter 'element') at System.Windows.Controls.ToolTipService.GetBetweenShowDelay(DependencyObject element) at System.Windows.Controls.PopupControlService.CloseToolTip(ToolTip tooltip) at System.Windows.Controls.PopupControlService.OnPostProcessInput(Object sender, ProcessInputEventArgs e) at System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(Tuple`2 postProcessInput, ProcessInputEventArgs processInputEventArgs) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.MouseDevice.Synchronize() at System.Windows.Input.MouseDevice.ChangeMouseCapture(IInputElement mouseCapture, IMouseInputProvider providerCapture, CaptureMode captureMode, Int32 timestamp) at System.Windows.Input.MouseDevice.Capture(IInputElement element, CaptureMode captureMode) at System.Windows.UIElement.CaptureMouse() at ToolTip.MainWindow.OnMouseLeftButtonDown(Object sender, MouseButtonEventArgs e) in D:\Workspace\Software\ToolTip\ToolTip\MainWindow.xaml.cs:line 64 at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, O bject args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(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() at ToolTip.App.Main()

Expected behavior: App should not crash.

Minimal repro: Please use the attached demo.sln and run it with .net 6 target framework. After the app window appears move your mouse into the window. A tooltip will be shown, which shows you the actual mouse position. Stop moving the mouse and wait 5 seconds until the tooltip disappears. Directly and quickly after the tooltip disappears quickly move your mouse a short distance and afterwards quickly do a left click.

Attached demo.sln: ToolTipBug.zip

miloush commented 2 years ago

Looks like duplicate of #6319 @SamBent does this help? I cannot reproduce under VS debugging but when I run Debug build without debugging I could reproduce couple of times and I managed under windbg too.

JNaumann86 commented 2 years ago

Hi, I am using IDE Jetbrains Rider and I can reproduce it in debug mode with success rate of 100%. I even have an easy work around to avoid this bug. On click action before doing the mouse capturing I just have to close the tooltip manually. I just wanted to create the bug to help making .net6 a bit more stable :)

SamBent commented 2 years ago

Yes, this helps a lot. This is the repro (and time-travel trace, sent by @miloush privately) I've been waiting for since March.

It's a dupe of #6319 in the sense the root cause is the same: the app and WPF's PopupControlService are both manipulating the tooltip object (setting toolTip.IsOpen), and sometimes confusing each other in the process. The details of how the manipulation happens might be different, but that doesn't matter much.

Some notes:

JNaumann86 commented 2 years ago

Hi thank you for the update!

I just wanted to state, that my workaround of closing the tooltip manually is not always working. Sometimes the bug still occurs, but with less frequency. Could you please estimate in which minor version upgrade of .Net6 the bug will be fixed?

Thank you!

czdietrich commented 1 year ago

Any news on this? This issue still states Investigate, is there currently active work on this?

dipeshmsft commented 1 year ago

@czdietrich, we have a fix for this. We are testing it right now. Once testing it complete, we will make a PR for this and other tooltip bugs.

czdietrich commented 1 year ago

Hi @dipeshmsft, thank you for the quick response and update to this issue. 👍

znakeeye commented 1 year ago

Tried running the demo.sln, but never got the crash. Are there any particular steps needed?

My system

czdietrich commented 1 year ago

So, what is the latest status to this issue? We got PRs for the different .NET versions.

Can we expect they will be part of the .NET service packs in February?

cmunforte commented 1 year ago

We are also waiting this fix to go into the .Net 4.8 Framework. Any ideas when a Windows Update will be available for our customers to download?

dipeshmsft commented 1 year ago

@czdietrich, we are reviewing the timelines for shipping this fix. I will respond on this thread with the schedule ASAP.

@cmunforte, can you raise a DTS bug for .NET Framework? Any changes in .NET Framework are done through the DTS process. The CSS representative of the corresponding enterprise needs to file a DTS bug for this change to be in .NET Framework along with the business impact and justification.

cmunforte commented 1 year ago

@dipeshmsft I don't know what a DTS bug is or how to raise it. Do you have a link?

werksarztzentrum commented 1 year ago

We need also a quick fix for .NET Framework 4.8, all our Windows 11 Users have this problem in WPF.

dipeshmsft commented 1 year ago

@werksarztzentrum we have started work on that front as well. @cmunforte, sorry I missed your question, were you able to find the link to open a DTS bug?

cmunforte commented 1 year ago

@dipeshmsft No, I did not find the link to open a DTS bug. Actually we have found a fix to this issue so it is not as urgent anymore. So after a bit of fiddling around I was able to fix this crash within our code by attaching to the "ToolTipOpening" event and setting "e.Handled" to true.

public ChromiumWebBrowser Browser;
this.Browser.ToolTipOpening += this.OnToolTipOpening;

private void OnToolTipOpening(object sender, ToolTipEventArgs e)
{
         // Fixes the System.ArgumentNullException within System.Windows.Controls.ToolTipService.GetBetweenShowDelay
         // Funnily enough it still shows the tooltip!
         e.Handled = true;
}

I have also mentioned the fix here with further details:

ToolTip Crash Fix

dipeshmsft commented 1 year ago

@cmunforte @czdietrich @JNaumann86 we have merged the fix in the release branches and the fix will be out in upcoming servicing release of .NET 6 and .NET 7.

dipeshmsft commented 1 year ago

@cmunforte @czdietrich @JNaumann86 can you verify if the latest release ( 7.0.5 / 6.0.16 ) resolves issues in your applications ?

dipeshmsft commented 1 year ago

As the fix is already merged, closing this issue now.

czdietrich commented 1 year ago

@cmunforte @czdietrich @JNaumann86 can you verify if the latest release ( 7.0.5 / 6.0.16 ) resolves issues in your applications ?

Latest tests seem to show that the issue is gone now. At least we were no able to reproduce the issue any longer, but due to its sporadic nature we cannot say it with 100% certainty, but it is very likely to be fixed.

We will now begin to roll out the fix to our customers (if it is not already indirectly fixed by Microsoft Update) and look out for new reports. If so, we will report back here.

Thank you very much that this issue seems now to be finally gone. It was really the hardest .NET issue we faced in the recent time of .NET and with the most negative effect on our customer base. And I kindly hope that such issues can be more prioritized in the future for a better overall experience.