Skip to content

Windows.Storage.Pickers.FileSavePicker.FileTypeChoices.Add throw System.InvalidCastException: 'Specified cast is not valid.' with PublishAOT=true #4743

Open
@optsing

Description

@optsing

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

  1. Create new WinAppSDK project
  2. Add <WindowsSdkPackageVersion>10.0.22621.45</WindowsSdkPackageVersion> and <PublishAot>true</PublishAot> to csproj
  3. 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions