HavenDV / H.NotifyIcon

TrayIcon for WPF/WinUI/Uno/MAUI
MIT License
545 stars 44 forks source link

TrayIcon.UpdateIcon (IntPtr handle) - System.InvalidOperationException: UpdateIcon failed. #132

Closed fstutzman closed 8 months ago

fstutzman commented 8 months ago

Describe the bug

We are receiving multiple crash reports from our crash reporting system (Appcenter), I will include the crash below.

What is interesting about this issue is we are not hearing about the crash from users. WIth over 450 reports of the crash, it would expect some users to write in and complain that the icon disappeared or the program crashed. But we are not hearing these reports.

Package: FreedomPlatform
Version: 2.25
OS: WINDOWS
Windows: 10.0.22621
Date: 2024-01-03T14:40:54.0825702Z

Exception Stack:
System.InvalidOperationException: UpdateIcon failed.
  at H.NotifyIcon.Core.TrayIcon.UpdateIcon(IntPtr handle)
  at H.NotifyIcon.TaskbarIcon.UpdateIcon(Icon value)
  at H.NotifyIcon.TaskbarIcon.<>c.<.cctor>b__257_7(DependencyObject sender, DependencyPropertyChangedEventArgs args)
  at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
  at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
  at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
  at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
  at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
  at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
  at H.NotifyIcon.TaskbarIcon.<OnIconSourceChanged>d__177.MoveNext()
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  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, Boolean preserveSyncCtx)
  at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
  at System.Threading.ExecutionContext.Run(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 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
  at System.Windows.Application.RunDispatcher(Object ignore)
  at System.Windows.Application.RunInternal(Window window)
  at FreedomPlatform.SingleInstanceManager.Run()
  at FreedomPlatform.App.Main(String[] args)

Steps to reproduce the bug

We are not able to reproduce the bug, which is confusing.

Expected behavior

No response

Screenshots

No response

NuGet package version

2.0.123

Platform

WPF

IDE

Visual Studio 2022

Windows Version

Windows 11, Windows 10

WindowsAppSDK Version

1.0

WindowsAppSDK Type

Packaged

Manifest

No response

Additional context

If anyone else is running into this crash, or has any other information on the trace, it would be much appreciated. Thank you.

HavenDV commented 8 months ago

The problem with this exception is that it is a failed Win32 API call and there is no way to find out the details. We can only guess at some conditions - for example, when the application is minimized or hidden, when Windows is hibernating, or some other unique environment conditions in which the application is still running, but the user is not directly interacting with it

HavenDV commented 8 months ago

I removed this exception in the latest release because it doesn't provide any benefit. https://github.com/HavenDV/H.NotifyIcon/commit/10e6f835161bfa7a2f16d91a6bc13955491b43dc

HavenDV commented 8 months ago

If there are no side issues here with updating the icon (which can sometimes have the wrong state, for example), then this can be closed

fstutzman commented 8 months ago

@HavenDV I will pass your feedback to our Windows lead and see if there is any followup, and respond accordingly. Thank you for your quick response.

fstutzman commented 8 months ago

@HavenDV Thank you, we discussed this and we will update to the latest version. I will go ahead and close this.