CommunityToolkit / Windows

Collection of controls for WinUI 2, WinUI 3, and Uno Platform developers. Simplifies and demonstrates common developer tasks building experiences for Windows with .NET.
https://aka.ms/windowstoolkitdocs
Other
596 stars 74 forks source link

SettingsControls 8.1.240821 produces trim warnings #498

Closed vilgotf closed 18 hours ago

vilgotf commented 2 months ago

Describe the bug

The app crashes during initialization.

Running under WinDbg reveales that the stowed exception is 0x80040154 (REGDB_E_CLASSNOTREG) with the following stack trace:

System_Private_CoreLib!System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32)+0x1b
WinRT_Runtime!WinRT.ActivationFactory.Get(System.String, System.Guid)+0x1aa
Microsoft_WinUI!Microsoft.UI.Xaml.Application.get__objRef_global__Microsoft_UI_Xaml_IApplicationStatics()+0x6b
Microsoft_WinUI!Microsoft.UI.Xaml.Application.Start(Microsoft.UI.Xaml.ApplicationInitializationCallback)+0x19
Expander_MRE!Expander_MRE.Program.Main(System.String[])+0xe4

Steps to reproduce

Create a new project from the "Blank App, Packaged (WinUI 3 in Desktop)" template and add
* CsWinRT `2.1.1`
* WindowsSdkPackageVersion `10.0.22621.38` (matching `TargetFramework`)
* SettingsControls 8.1.240821

(ensure WASDK is at version `1.6.240829007`, this was already the case for me)

Then, 
1. Add `<controls:SettingsExpander />` to `MainWindow.xaml`
2. Start the project in release mode (the template included publish profile enables `PublishedTrimmed` for release builds)
3. Crash on startup

Expected behavior

There are no trim warnings, app does not crash on startup.

Screenshots

No response

Code Platform

Windows Build Number

Other Windows Build number

Windows 11 23H2

App minimum and target SDK version

Other SDK version

No response

Visual Studio Version

2022

Visual Studio Build Number

17.11.35222.181

Device form factor

Desktop

Additional context

Discovered this issue when trying to enable NativeAOT for my project, which seems to be blocked by this issue.

Although I'm unable to reproduce the behaviour in my MRE, my original project is able to render the expander, but throws the following exception when expanding it:

System.ExecutionEngineException
  HResult=0x80131506

  This exception was originally thrown at this call stack:
    WinRT.ExceptionHelpers.ThrowExceptionForHR.__Throw|38_0(int)
    ABI.Microsoft.UI.Xaml.Controls.IStyleSelectorMethods.SelectStyle(WinRT.IObjectReference, object, Microsoft.UI.Xaml.DependencyObject)
    CommunityToolkit.WinUI.Controls.SettingsExpander.ItemsRepeater_ElementPrepared(Microsoft.UI.Xaml.Controls.ItemsRepeater, Microsoft.UI.Xaml.Controls.ItemsRepeaterElementPreparedEventArgs) in SettingsExpander.ItemsControl.cs
    ABI.Windows.Foundation.TypedEventHandlerMethods<TSender, TSenderAbi, TResult, TResultAbi>.Abi_Invoke(System.IntPtr, TSender, TResult)
    WinRT.GenericTypeInstantiations.Windows_Foundation_TypedEventHandler_2_Microsoft_UI_Xaml_Controls_ItemsRepeater__Microsoft_UI_Xaml_Controls_ItemsRepeaterElementPreparedEventArgs.Do_Abi_Invoke(System.IntPtr, System.IntPtr, System.IntPtr)

Inner Exception 1:
InvalidCastException: Specified cast is not valid.

Help us help you

Yes, but only if others can assist.

michael-hawker commented 2 months ago

@vilgotf 8.1 was built against 1.5 and hasn't been tested against AOT scenarios yet. You'll at least want the 1.6 bits on our preview feeds: https://aka.ms/wct/wiki/previewpackages

See https://github.com/CommunityToolkit/Tooling-Windows-Submodule/issues/205

TheJoeFin commented 1 day ago

I am seeing SettingsControls failing to parse XAML when under AOT. Is there a timeline to update this control to be AOT compatible?

WindowsAppSDK 1.6.241114003 CommunityToolkit.WinUI.Controls.SettingsControls 8.1.240916

michael-hawker commented 18 hours ago

@vilgotf @TheJoeFin I'm going to close this one out as it was specifically about 8.1 which is NOT AOT compatible (as I mentioned above); 8.2 will be the first version that's AOT compatible with WASDK 1.6. There was another issue filed, where I commented that I have not seen an issue with it working there. https://github.com/CommunityToolkit/Windows/issues/568#issuecomment-2498695680

Please check your versions and try the latest preview to see if that works for you, thank you!