CsWinRT
CsWinRT copied to clipboard
Lost exception info (and exception type) across ABI boundary
Describe the bug
I have a managed WinRT type, CanvasEffect
(a class implementing the ICanvasImage
WinRT interface from Win2D), that also implements a classic COM interface, ICanvasImageInterop
. This type can thrown an InvalidOperationException
(here) from one of the implemented interface methods. CsWinRT correctly handles this in the marshalling stub, catches the exception and calls ExceptionHelpers.SetExceptionInfo
, but on the other side it seems like some information is lost. Specifically, while I am seeing the same HRESULT being thrown (-2146233079
), I'm getting a COMException
, rather than InvalidOperationException
.
Note: that HRESULT is COR_E_INVALIDOPERATION
, defined here.
I noticed this because I have a unit test, CanvasEffect_EffectNotRegisteringAnOutputNode
, which is specifically checking for that exception type, and I noticed that while it used to work correctly, it's now failing, as the resulting exception is just a COMException
.
Note that the original exception message is not present in the exception data either, it just seems to be lost:
To Reproduce
- Clone https://github.com/Sergio0694/ComputeSharp
- Run the
CanvasEffect_EffectNotRegisteringAnOutputNode
test
Expected behavior
The test should (presumably?) re-throw the InvalidOperationException
, ideally with the original message too.
Version Info
- Tested with .NET 7 and .NET 8, same behavior
- CsWinRT 2.0.3 and 2.0.4, same behavior
- Win2D 1.1.0
We might need to add that error code to the mapping here and also look at why we aren't bringing back the old exception from the error info itself or why it is getting lost. I assume none of this is cross processes and is within the same process?
"I assume none of this is cross processes and is within the same process?"
Yup! This is all in-proc, it's just a simple app using Win2D and doing interop with some custom types.
I can put together a simpler repo if it helps, unless just reproing from that repo directly is ok, let me know what you prefer 🙂
"I assume none of this is cross processes and is within the same process?"
Yup! This is all in-proc, it's just a simple app using Win2D and doing interop with some custom types.
I can put together a simpler repo if it helps, unless just reproing from that repo directly is ok, let me know what you prefer 🙂
Small repro is always useful I think?
Did it work before #1335?