CsWinRT
CsWinRT copied to clipboard
Native AOT: InvalidCastException in CommunityToolkit when using GridSplitter
trafficstars
Description
This bug/crash has been reported previously here: https://github.com/CommunityToolkit/Windows/issues/612
System.InvalidCastException: Specified cast is not valid
at System.Runtime.RuntimeExports.RhUnbox2(MethodTable*, Object) + 0x3f
at CommunityToolkit.WinUI.Controls.GridSplitter.IsStarColumn(ColumnDefinition) + 0x53
at CommunityToolkit.WinUI.Controls.GridSplitter.OnDragHorizontal(Double) + 0xf9
at CommunityToolkit.WinUI.Controls.SizerBase.OnManipulationDelta(ManipulationDeltaRoutedEventArgs) + 0x11b
at ABI.Microsoft.UI.Xaml.Controls.IControlOverrides.Do_Abi_OnManipulationDelta_15(IntPtr, IntPtr) + 0x58
Steps To Reproduce
See example project: Crash.zip To reproduce the crash, grab the GridSplitter handle and try to move it -> app crashes
Important: Run in Native Aot (not CoreCLR) - so I had to publish the app, then install and run it
Expected Behavior
No crash
Version Info
CsWinRT 2.2
Additional Context
No response
I get a similar exception with UWP/.NET9 once my app switches from the custom splash screen to the app's main surface:
at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32 hr)
at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
at ABI.Windows.UI.Xaml.IFrameworkElementOverridesMethods.MeasureOverride(IObjectReference _obj, Size availableSize)
at Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)
at Windows.UI.Xaml.FrameworkElement.Windows.UI.Xaml.IFrameworkElementOverrides.MeasureOverride(Size availableSize)
at ABI.Windows.UI.Xaml.IFrameworkElementOverrides.Do_Abi_MeasureOverride_0(IntPtr thisPtr, Size availableSize, Size* result)
Unfortunately I could not yet drill it down to the actual root cause in my project. 🤔