microsoft / microsoft/WindowsAppSDK
Windows.Storage.Pickers.FileSavePicker.FileTypeChoices.Add throw System.InvalidCastException: 'Specified cast is not valid.' with PublishAOT=true
@manodasanW is already working on this.
Since Sep 26, 2024.
- Dominant language
- C++
- Stars
- 4.7k
- Forks
- 471
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 28
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
1. Create new WinAppSDK project
2. Add `10.0.22621.45` and `true` 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_
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.