A set of .NET Framework managed libraries for developing graphical user interfaces.
Hello,
Just would like to give an update here for those who also encountered the problem.
We created a Microsoft ticket for this issue and logs were collected from my machine. But they cannot see any anomaly and asked us to provide a simple winform application where it can be reproduced. We failed to reproduce this problem on a simple app and there it always works.
After more research related to taskbar icon problem, I found this: https://www.reddit.com/r/WindowsHelp/comments/1grzcdy/comment/mrgsllj/. And after trying the suggestion here, I observed that the taskbar gets refreshed after changing some settings, so I looked for a way to refresh the taskbar in C# and found this: https://www.reddit.com/r/Windows11/comments/12ygqei/how_can_i_refresh_the_taskbar_after_making_some/?rdt=45820.
We ended up refreshing the taskbar using the SendMessage function (from user32.dll) after setting the icon and this worked for us.
private const int HWND_BROADCAST = 0xffff;
private const int WM_SETTINGCHANGE = 0x001a;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, string lParam);
//refresh taskbar to prevent blank (default) exe icon
SendMessage((IntPtr)HWND_BROADCAST, WM_SETTINGCHANGE, IntPtr.Zero, "Policy");
Hope this can help others who are experiencing the same problem.