CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

Custom exception messages set in C++/WinRT hresult_error do not appear on C# side

Open lukasf opened this issue 1 year ago • 0 comments

Describe the bug

Custom exception messages set in C++/WinRT hresult_error do not appear on C# side.

To Reproduce

In C++/WinRT, throw an exception with a custom message:

throw winrt::hresult_error(0xC00D1001, L"Test"); // Self defined HRESULT in FACILITY_ITF

When I catch the exception in C++/WinRT and call .message() on the hresult_error, I see the expected string:

Test

But when I catch the same exception using a C# client through CsWinRT, I get this poor message:

0xC00D1001

Similar misbehavior occurs when I use a known HRESULT with a custom message:

throw winrt::hresult_error(E_FAIL, "Test");

When catching it in C++/WinRT, I get the expected message:

Test

But when I catch the same exception from a C# client, I get this error:

Error HRESULT E_FAIL has been returned from a call to a COM component.

Expected behavior If I specify an exception message in C++/WinRT, then I expect that this message is shown in C#, unmodified. But instead, for custom HRESULT values, the hex HRESULT is shown, and for known messages, the default message is shown instead of the custom message I have set (and which is available in the ErrorInfo set for the current thread).

Version Info CsWinRT 2.0.0, 2.0.1

Additional context The VS debug output mentions the error message when it is thrown:

WinRT originate error - 0x80004005 : 'Test'.

lukasf avatar Nov 23 '22 21:11 lukasf