Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMException 0x8001010E thrown in PrepareContextMenuWindow #186

Open
ChristianGalla opened this issue Dec 29, 2024 · 1 comment
Open

COMException 0x8001010E thrown in PrepareContextMenuWindow #186

ChristianGalla opened this issue Dec 29, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ChristianGalla
Copy link
Contributor

Describe the bug

Hi,

nice project!

After updating my app AutoStartConfirm from .NET 8 to 9 and H.NotifyIcon.WinUI from 2.0.124 to 2.2.0, creating a new TaskbarIcon instance throws the following error:

System.Runtime.InteropServices.COMException
  HResult=0x8001010E
  Message=
  Source=WinRT.Runtime
  StackTrace:
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32 hr) in WinRT\ExceptionHelpers.cs:line 134
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr) in WinRT\ExceptionHelpers.cs:line 122
   at ABI.Microsoft.UI.Xaml.IWindowMethods.get_Content(IObjectReference _obj)
   at Microsoft.UI.Xaml.Window.get_Content()
   at H.NotifyIcon.TaskbarIcon.<>c__DisplayClass25_0.<<PrepareContextMenuWindow>b__1>d.MoveNext()
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

While debugging I had a look at the failing code of this library and I noticed the following:
There is a line to delay code execution for 1 ms. Before this line window.Content is set, after the wait trying to access window.Content throws the mentioned exception.

await Task.Delay(1).ConfigureAwait(true);
flyout.ShowAt(window.Content, new FlyoutShowOptions
{
    ShowMode = FlyoutShowMode.Transient,
});

There is no error message, but 0x8001010E usually means RPC_E_WRONG_THREAD. According to the Visual Studio thread window between these lines the executing thread switches from main to another Worker Thread ".NET TP Worker". Because access of GUI elements is only possible in the main thread, execution fails.

According to the documentation ConfigureAwait not guarantees continuation in the calling thread.

Maybe the await is a hack for previous versions that is not needed anymore and can be removed? If it is still needed, switching to something like Dispatcher.Invoke may be needed.

Steps to reproduce the bug

No response

Expected behavior

No error is thrown

Screenshots

No response

NuGet package version

Microsoft.WindowsAppSDK 1.6.241114003
H.NotifyIcon.WinUI 2.2.0

Platform

WinUI

IDE

Visual Studio 2022

Windows Version

Windows 10

WindowsAppSDK Version

Other

WindowsAppSDK Type

Unpackaged

Manifest

No response

Additional context

Maybe this is related to issue #175?

@ChristianGalla ChristianGalla added the bug Something isn't working label Dec 29, 2024
@ChristianGalla ChristianGalla changed the title COMException 0x8001010E thrown after .NET 9 update in PrepareContextMenuWindow COMException 0x8001010E thrown in PrepareContextMenuWindow Dec 30, 2024
@ChristianGalla
Copy link
Contributor Author

I was able to reproduce this issue on .NET 8 on every NotifyIcon 2.1 and 2.2 version.
2.0.131 is running fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant