question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullReferenceException on ToolTipChanged on Windows 10

See original GitHub issue

Describe the bug

I’m developing on Windows 11 and test my app on Windows 10 21H2. Everything works fine on Windows 11. However on Windows, my app crashes when I pass the mouse on the icon in the system tray.

Message:

Object reference not set to an instance of an object.

Call stack:

   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
   at H.NotifyIcon.TaskbarIcon.OnToolTipChange(Object sender, Boolean visible)
   at H.NotifyIcon.Core.MessageWindow.ProcessWindowMessage(UInt32 msg, WPARAM wParam, LPARAM lParam)
   at H.NotifyIcon.Core.MessageWindow.OnWindowMessageReceived(HWND hWnd, UInt32 msg, WPARAM wParam, LPARAM lParam)

Steps to reproduce the bug

  1. Be on Windows 10 build 19044.2075 (21H2) (does not reproduce on Windows 11)
  2. Using H.NotifyIcon.WinUI 2.0.68` and above.
  3. Create a windowless WinUI 3 app using this sample: https://github.com/HavenDV/H.NotifyIcon/tree/master/src/apps/H.NotifyIcon.Apps.WinUI.Windowless
  4. Update WinAppSDK to 1.2.220930.4-preview2 (I admit I didn’t try with an older version)
  5. Have a XAML similar to
<tb:TaskbarIcon
        x:Key="NotifyIcon"
        Visibility="Visible"
        ToolTipText="MyTooltip"
        ContextMenuMode="SecondWindow">
        [...]
    </tb:TaskbarIcon>
  1. Start the app from Visual Studio 2022
  2. Pass the mouse above the icon in the systray, without clicking. image
  3. NRE exception gets raised and don’t seem to be handled.
  4. App end up crashing 😃

Expected behavior

No crash 😃 Tooltip should appear.

Screenshots

No response

NuGet package version

2.0.68 Also tried with 2.0.73

Platform

WinUI

IDE

Visual Studio 2022

Windows Version

Windows 10

WindowsAppSDK Version

Other

WindowsAppSDK Type

Packaged

Manifest

No response

Additional context

Windows 10 build 19044.2075 (21H2)

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
justinsoderstromcommented, Nov 8, 2022

I can see something similar happening on my system (also Windows 10) with the WinUI.Windowless example project. However in my case the null reference exception is thrown as soon as it reaches line 231 in TaskBarIcon.ToolTips.cs. This line causes issues:

TrayToolTipResolved.IsOpen = true;

While debugging I can see TrayToolTipResolved is defined so maybe the error is somewhere deeper in the IsOpen setter? The stack trace I get

   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
   at ABI.Microsoft.UI.Xaml.Controls.IToolTipMethods.set_IsOpen(IObjectReference _obj, Boolean value)  
   at H.NotifyIcon.TaskbarIcon.OnToolTipChange(Object sender, Boolean visible) in C:\\Projects\\H.NotifyIcon\\src\\libs\\H.NotifyIcon.Shared\\TaskbarIcon.ToolTips.cs:line 231"

I added a trivial check to WinUI to bypass this area. Please check 74 version on NuGet. But I’m guessing the problem is deeper, it’s just a temporary solution to bypass NRE.

NRE no longer occurs for me on 74 version.

0reactions
HavenDVcommented, Nov 8, 2022

I can see something similar happening on my system (also Windows 10) with the WinUI.Windowless example project. However in my case the null reference exception is thrown as soon as it reaches line 231 in TaskBarIcon.ToolTips.cs.

This line causes issues:

TrayToolTipResolved.IsOpen = true;

While debugging I can see TrayToolTipResolved is defined so maybe the error is somewhere deeper in the IsOpen setter?

The stack trace I get

   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
   at ABI.Microsoft.UI.Xaml.Controls.IToolTipMethods.set_IsOpen(IObjectReference _obj, Boolean value)  
   at H.NotifyIcon.TaskbarIcon.OnToolTipChange(Object sender, Boolean visible) in C:\\Projects\\H.NotifyIcon\\src\\libs\\H.NotifyIcon.Shared\\TaskbarIcon.ToolTips.cs:line 231"

I added a trivial check to WinUI to bypass this area. Please check 74 version on NuGet. But I’m guessing the problem is deeper, it’s just a temporary solution to bypass NRE.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I fix the error: System.NullReferenceException
A NullReferenceException exception is thrown when you try to access a member on a type whose value is null. A NullReferenceException exception ......
Read more >
NullReferenceException Class (System)
The exception that is thrown when there is an attempt to dereference a null object reference.
Read more >
How to solve System.NullReferenceException?
A NullReferenceException typically occurs when you try to access a member or call a method on an object that is currently null.
Read more >
NullReferenceException if you use CommandBuilder
NullReferenceException exception that occurs when you use the CommandBuilder object. Original product version: Visual Basic .NET
Read more >
Object reference not set to an instance of an object.
View is receiving the Model value as Null. Debug the respective controller action to verify why is it returning null. If it is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found