Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native AOT: InvalidCastException when using GridSplitter #612

Open
3 of 24 tasks
tipa opened this issue Jan 25, 2025 · 6 comments
Open
3 of 24 tasks

Native AOT: InvalidCastException when using GridSplitter #612

tipa opened this issue Jan 25, 2025 · 6 comments
Labels
nativeaot The dependency on dotnet NativeAOT
Milestone

Comments

@tipa
Copy link

tipa commented Jan 25, 2025

Describe the bug

I'm seeing this crash reported on a device with Windows 10.0.19045. I wasn't able to reproduce it locally on a Windows 11 machine

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

I'm using CommunityToolkit.WinUI.Controls.Sizers 8.2.241112-preview1 in a .NET9 WinUI3 app that is compiled using Native AOT

Steps to reproduce

I'm essentially only using a GridSplitter and adjusting Grid.Row and Grid.Column in code

<controls:GridSplitter x:Name="gridSplitter" Grid.Row="1" Grid.Column="1" />

Expected behavior

No crash

Screenshots

No response

Code Platform

  • UWP
  • WinAppSDK / WinUI 3
  • Web Assembly (WASM)
  • Android
  • iOS
  • MacOS
  • Linux / GTK

Windows Build Number

  • Windows 10 1809 (Build 17763)
  • Windows 10 1903 (Build 18362)
  • Windows 10 1909 (Build 18363)
  • Windows 10 2004 (Build 19041)
  • Windows 10 20H2 (Build 19042)
  • Windows 10 21H1 (Build 19043)
  • Windows 10 21H2 (Build 19044)
  • Windows 10 22H2 (Build 19045)
  • Windows 11 21H2 (Build 22000)
  • Other (specify)

Other Windows Build number

No response

App minimum and target SDK version

  • Windows 10, version 1809 (Build 17763)
  • Windows 10, version 1903 (Build 18362)
  • Windows 10, version 1909 (Build 18363)
  • Windows 10, version 2004 (Build 19041)
  • Windows 10, version 2104 (Build 20348)
  • Windows 11, version 22H2 (Build 22000)
  • Other (specify)

Other SDK version

No response

Visual Studio Version

2022

Visual Studio Build Number

No response

Device form factor

No response

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item.

@tipa tipa changed the title InvalidCastException when using GridSplitter Native AOT: InvalidCastException when using GridSplitter Jan 26, 2025
@Sergio0694
Copy link
Member

@tipa can you try again with the latest WCT 8.2-preview2 build that went out today, and CsWinRT 2.2.0? Thank you!

@tipa
Copy link
Author

tipa commented Jan 28, 2025

Still crashes with WCT 8.2-preview2 & CsWinRT 2.2.0.

But adding line resolves it for me:
[assembly: GeneratedWinRTExposedExternalType(typeof(GridLength))]

@michael-hawker michael-hawker added this to the 8.2 milestone Feb 3, 2025
@michael-hawker
Copy link
Member

@Sergio0694 so since GridLength is a system type is this an issue in CsWinRT or do we need to annotate something in the Toolkit?

@Sergio0694
Copy link
Member

This feels like a CsWinRT issue, possibly. cc. @manodasanW

@Arlodotexe Arlodotexe added the nativeaot The dependency on dotnet NativeAOT label Feb 6, 2025
@Arlodotexe Arlodotexe moved this to 🆕 New in Toolkit 8.x Feb 6, 2025
@michael-hawker
Copy link
Member

Talked quick to @manodasanW and seems like it may smell like a C#/WinRT issue.

@tipa do you have a small minimal reproduction project of the issue you could zip up? If so, would you mind opening an issue over there, attaching it, and linking back to this one?

I did see this GridLength issue over there, but not sure if related, seems different? microsoft/CsWinRT#1417

@tipa
Copy link
Author

tipa commented Feb 7, 2025

@michael-hawker done: microsoft/CsWinRT#1917

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nativeaot The dependency on dotnet NativeAOT
Projects
Status: 🆕 New
Development

No branches or pull requests

4 participants