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

Bug: COMException often has empty error message #1918

Open
whiskhub opened this issue Feb 7, 2025 · 0 comments
Open

Bug: COMException often has empty error message #1918

whiskhub opened this issue Feb 7, 2025 · 0 comments

Comments

@whiskhub
Copy link

whiskhub commented Feb 7, 2025

Description

COMExceptions thrown by WinRT code often times only have an empty error message. This greatly impacts the developer experience, especially for beginners. To understand the error, the HResult must be researched manually, which can be confusing if you don't know what it means.

The easiest to reproduce with is when setting some WinUI component value on the wrong thread (RPC_E_WRONG_THREAD -2147417842)

Image

I assume it is a CsWinRT bug, because the error message (The application called an interface that was marshalled for a different thread.) is correctly shown in C++ (also in the IRestrictedErrorInfo) (C++WinRT):
Image

Steps To Reproduce

  1. Have a WinUI 3 C# app
  2. Access a UI component from another thread, e.g.:
await Task.Run(() =>
{
    try
    {
        myButton.Content = "WRONG THREAD";
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.Message);
    }
});
  1. Check the exception message.

Expected Behavior

The COMException message should contain a message.

It should be the same message as in the C++WinRT exception.

If there is no specific exception message set, it would be nice if CsWinRT could at also generate a message based on the HResult code as a fallback.

Version Info

CsWinRT 2.2.0
Windows App SDK 1.6 or 1.7
.NET 8/9

Additional Context

No response

@whiskhub whiskhub changed the title Bug: COMException has often empty error message Bug: COMException often has empty error message Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant