wpf: (ToolTip ) System.ArgumentNullException: Value cannot be null. (Parameter 'element')

  • .NET Core Version: 6.0.3
  • Windows version: Win10
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Repros on .NET 4.8.1 only.
  • Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc…)?: No

Problem description: App Crash … the Problem should be resolved but it comes again and again.

BTW: I don’t use any Tooltip in my App, regardless the problem come again and again during the working!

Actual behavior:

Application: Project.exe CoreCLR Version: 6.0.322.12309 .NET Version: 6.0.3 Description: The process was terminated due to an unhandled exception. Exception Info: 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.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 CefSharp.Wpf.ChromiumWebBrowser.OnMouseDown(MouseButtonEventArgs e) in C:\projects\cefsharp\CefSharp.Wpf\ChromiumWebBrowser.cs:line 2239 at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 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.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, Object 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 Application.Desktop.App.Main()

Expected behavior: App should not be crashed

How could i solve the Problem fastly ?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 56 (15 by maintainers)

Most upvoted comments

Many of our customers are experiencing this exception (and exact same call stack) as well. Not sure if this helps, but just thought I’d add what we have found:

  • Our application is .Net Framework 4.8 (not .Net 6.0)
  • Our application also uses CefSharp (a fairly old version: 75.1.143.0)
  • All users who have reported the crash have been on Windows 11

Steps to replicate:

  • Hover over a CEF (browser) button until a tooltip shows
  • Wait for 5 seconds or so and move to another button and wait again for another tooltip
  • It usually crashes at this point (sometimes need to repeat the above steps a few times)

Our devs were unable to replicate this on a Windows 10 development machine (with just the .Net 4.8 framework installed), But if they downloaded and installed .Net 4.8.1, they CAN reproduce it with the same application (not rebuilt) fairly easily.

In Windows 10 (with .Net 4.8), after waiting sufficiently long enough, the tooltip auto-disappears. After installing .Net Framework 4.8.1, we noticed the tooltip does not auto-disappear.

We have tried various combinations of the Switch.UseLegacyToolTipDisplay and related settings mentioned in the article in the previous post, but with no success.

It’s a little embarrassing as we have no way to trap the exception, and some users are getting this exception many times a day.

If I understood correctly, they can already reproduce the issue and have a fix for it. But unfortunately, there is no new information since.

We’re using CefSharp and seeing it about 600 times a day for our users.

~95% are on Windows 11. I understand that a time-travel trace might help, so we’ll try and get one. So far we’ve been unable to reproduce it internally.

We encounter the same issue even without using CefSharp. While we were also using CefSharp to show web content, we switched to WebView2 some time ago and still see this issue.

In our case the application is mixed WinForms / WPF and the crashes are not necessarily related to showing web content.

Setup: Windows 10, .NET 6.0.8

We need to find a solution for this issue. We still receive crash reports for this issue and to be fair, it is kind of embarrassing for us to receive negative feedback about an issue we cannot really change anything about.

Crashing the whole application just because there is some issue with closing a tooltip feels just completely wrong. Even though we are not able to reproduce the origin of this issue, we know it started to occur after latest changes to the tooltip behavior in WPF.

While I am not a fan of fixing symptoms, I am even less a fan of apologizing to customers when they lose their current progress just because of this tooltip issue.

Can we at least provide a workaround to just not throw this exception (e.g. with an app switch) even though we expect it usually not to happen?

Thanks @hhu-mahmoud for the confirmation. Closing this issue now.

For those seeing this issue in the context of CefSharp, there is a potential workaround available at https://github.com/cefsharp/CefSharp/issues/4048#issuecomment-1425020882

@hhu-mahmoud - Are you seeing this issue with 6.0.5 as well ?

Unfortunately I’ve not been able to reproduce the problem in a simple application but I’ve also discovered that in my actual application the issue is no longer reproducible after runtime 6.0.3. Our current release is targeting 6.0.1 and I am able to trigger the issue on 6.0.1 and 6.0.2, but 6.0.3, 6.0.4 and 6.0.5 all appear to have the issue solved in my case at least.

No sample project needed. The exact commit is highlighted above - with a 100% valid fix. Please just push it now, and release 6.0.4 asap.

@SamBent We are also facing this issue. We upgraded recently to 6.0.x, We are constantly facing app crash. This issue occurs when tool tip is invoked as soon as xaml is loaded. This happens for wpf controls not any third party.

CurrentDomain FirstChanceException Message: Value cannot be null. (Parameter ‘element’) Type: System.ArgumentNullException at System.Environment.get_StackTrace() at ApplicationName.App.CurrentDomain_FirstChanceException(Object sender, FirstChanceExceptionEventArgs e) in App.xaml.cs:line 128 at System.Windows.Controls.ToolTipService.GetBetweenShowDelay(DependencyObject element) at System.Windows.Controls.PopupControlService.CloseToolTip(ToolTip tooltip) at System.Windows.Controls.PopupControlService.PromotePendingToolTipToCurrent(TriggerAction triggerAction) at System.Windows.Controls.PopupControlService.<>c__DisplayClass9_0.<BeginShowToolTip>b__0(Object s, EventArgs e) at System.Windows.Threading.DispatcherTimer.FireTick() 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) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj) 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, 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, Object 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 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 ApplicationName.App.Main()

The problem was introduced in https://github.com/dotnet/wpf/pull/4623

https://github.com/dotnet/wpf/blob/869d4e0ec775d51ca50544a2473aafff1c1da813/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs#L602

A simple fix would look something like

 int betweenShowDelay = owner == null ? 0 : ToolTipService.GetBetweenShowDelay(owner);

The GetOwner method potentially returns null with other references performing null checks.