Open
Description
Describe the bug
Windows.Storage.Pickers.FileSavePicker.FileTypeChoices.Add throw System.InvalidCastException: 'Specified cast is not valid.' with PublishAOT=true
With PublishAOT=false everything works fine.
Steps to reproduce the bug
- Create new WinAppSDK project
- Add
<WindowsSdkPackageVersion>10.0.22621.45</WindowsSdkPackageVersion>
and<PublishAot>true</PublishAot>
to csproj - Add to myButton_Click
var picker = new Windows.Storage.Pickers.FileSavePicker();
WinRT.Interop.InitializeWithWindow.Initialize(picker, WinRT.Interop.WindowNative.GetWindowHandle(this));
picker.FileTypeChoices.Add("Text file", [".txt"]);
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
var file = await picker.PickSaveFileAsync();
Expected behavior
After clicking on the button, the Save File dialog box should be displayed
Screenshots
No response
NuGet package version
Windows App SDK 1.6.0: 1.6.240829007
Packaging type
Packaged (MSIX)
Windows version
Insider Build (xxxxx)
IDE
Visual Studio 2022-preview
Additional context
No response