CsWinRT
CsWinRT copied to clipboard
System.InvalidCastException: 'Specified cast is not valid.' on the staging/AOT branch
Describe the bug
WinRT.Runtime.dll!WinRT.ExceptionHelpers.ThrowExceptionForHR.__Throw|38_0(int hr = -2147467262) line 115
: D:\source\repos\microsoft\CsWinRT\src\WinRT.Runtime\ExceptionHelpers.cs(115)
WinRT.Runtime.dll!WinRT.ExceptionHelpers.ThrowExceptionForHR(int hr = -2147467262) line 118
: D:\source\repos\microsoft\CsWinRT\src\WinRT.Runtime\ExceptionHelpers.cs(118)
WinRTServerTest.dll!ABI.WinRTServer.ITestClassClassMethods.HelloAsync(WinRT.IObjectReference _obj = {WinRT.ObjectReference<WinRT.Interop.IUnknownVftbl>}, WinRTServer.BinaryDelegate func = {Method = {System.Reflection.RuntimeMethodInfo}}, int x = 24, int y = 35) line 556
: D:\source\repos\WinRTServer\WinRTServerTest\obj\x64\Debug\net8.0-windows10.0.22621.0\win-x64\Generated Files\CsWinRT\WinRTServer.cs(556)
WinRTServerTest.dll!WinRTServer.TestClass.HelloAsync(WinRTServer.BinaryDelegate func = {Method = {System.Reflection.RuntimeMethodInfo}}, int x = 24, int y = 35) line 254
: D:\source\repos\WinRTServer\WinRTServerTest\obj\x64\Debug\net8.0-windows10.0.22621.0\win-x64\Generated Files\CsWinRT\WinRTServer.cs(254)
WinRTServerTest.dll!Program.<Main>$(string[] args = {string[0]}) line 15
: D:\source\repos\WinRTServer\WinRTServerTest\Program.cs(15)
WinRTServerTest.dll!Program.<Main>(string[] args = {string[0]})
Inner exception:
System.Private.CoreLib.dll!System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(int errorCode) line 1259
: System.Runtime.InteropServices\Marshal.cs(1259)
WinRT.Runtime.dll!WinRT.ComWrappersSupport.CreateCCWForObjectForABI(object obj = {System.Threading.Tasks.TaskToAsyncOperationAdapter<WinRTServer.HelloStruct>}, System.Guid iid = {System.Guid}) line 172
: D:\source\repos\microsoft\CsWinRT\src\WinRT.Runtime\ComWrappersSupport.net5.cs(172)
WinRT.Runtime.dll!WinRT.ComWrappersSupport.CreateCCWForObjectForMarshaling(object obj = {System.Threading.Tasks.TaskToAsyncOperationAdapter<WinRTServer.HelloStruct>}, System.Guid iid = {System.Guid}) line 1165
: D:\source\repos\microsoft\CsWinRT\src\WinRT.Runtime\ComWrappersSupport.cs(1165)
WinRT.Runtime.dll!WinRT.MarshalInspectable<Windows.Foundation.IAsyncOperation<WinRTServer.HelloStruct>>.CreateMarshaler2(Windows.Foundation.IAsyncOperation<WinRTServer.HelloStruct> o = {System.Threading.Tasks.TaskToAsyncOperationAdapter<WinRTServer.HelloStruct>}, System.Guid iid = {System.Guid}, bool unwrapObject = true) line 1789
: D:\source\repos\microsoft\CsWinRT\src\WinRT.Runtime\Marshalers.cs(1789)
WinRT.Runtime.dll!WinRT.MarshalInterface<Windows.Foundation.IAsyncOperation<WinRTServer.HelloStruct>>.CreateMarshaler2(Windows.Foundation.IAsyncOperation<WinRTServer.HelloStruct> value = {System.Threading.Tasks.TaskToAsyncOperationAdapter<WinRTServer.HelloStruct>}, System.Guid iid = {System.Guid}) line 1619
: D:\source\repos\microsoft\CsWinRT\src\WinRT.Runtime\Marshalers.cs(1619)
WinRT.Runtime.dll!WinRT.MarshalInterface<Windows.Foundation.IAsyncOperation<WinRTServer.HelloStruct>>.FromManaged(Windows.Foundation.IAsyncOperation<WinRTServer.HelloStruct> value = {System.Threading.Tasks.TaskToAsyncOperationAdapter<WinRTServer.HelloStruct>}) line 1647
: D:\source\repos\microsoft\CsWinRT\src\WinRT.Runtime\Marshalers.cs(1647)
To Reproduce
- git clone https://github.com/hez2010/WinRTServer
- switch to your build of CsWinRT and projections
A convenient way to switch to your customized projection is:
<FrameworkReference Remove="Microsoft.Windows.SDK.NET.Ref" />
<Reference Include="Microsoft.Windows.SDK.NET">
<HintPath>path\to\Microsoft.Windows.SDK.NET.dll</HintPath>
</Reference>
Expected behavior No exception should be thrown.
Version Info CsWinRT on staging/AOT branch: 91fca8cd846d5ed351c45c5d842abef0ad964cc7
Additional context
Seems that async is broken.