Bug: COMException often has empty error message
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)
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):
Steps To Reproduce
- Have a WinUI 3 C# app
- Access a UI component from another thread, e.g.:
await Task.Run(() =>
{
try
{
myButton.Content = "WRONG THREAD";
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
});
- 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