FileSavePicker.FileTypeChoices throws InvalidCastException
See original GitHub issueDescribe the bug
Trying to execute any methods of folderPicker.FileTypeFilter
will throw an exception.
Steps to reproduce the bug
Steps to reproduce the behavior:
var savePicker = new FileSavePicker();
//Make folder Picker work in Win32
IntPtr windowHandle = (App.Current as App).WindowHandle;
InitializeWithWindowWrapper initializeWithWindowWrapper = InitializeWithWindowWrapper.FromAbi(savePicker.ThisPtr);
initializeWithWindowWrapper.Initialize(windowHandle);
folderPicker.FileTypeFilter.Add("*");
savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
savePicker.SuggestedFileName = "OUTPUT";
Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();
textBox.Text = file!= null ? file.Name: string.Empty;
- Run the app, click the Browse button.
- The app will crash with exception
System.InvalidCastException
(“Specified cast is not valid”).
| Name | Value | Type – | – | – | – ▶ | savePicker.FileTypeChoices.Add(“Plain Text”, new List<string>() { “.txt” }); | ‘savePicker.FileTypeChoices.Add(“Plain Text”, new List<string>() { “.txt” })’ threw an exception of type ‘System.InvalidCastException’ | void {System.InvalidCastException}
Expected behavior
A file save picker is opened. User can pick a file, then it’s path is shown in textbox.
Screenshots
Version Info
NuGet package version: [Microsoft.WinUI 3.0.0-preview2.200713.0]
Windows app type:
UWP | Win32 |
---|---|
No | Yes |
Windows 10 version | Saw the problem? |
---|---|
Insider Build (20231) | Yes |
May 2020 Update (19041) | |
November 2019 Update (18363) | |
May 2019 Update (18362) | |
October 2018 Update (17763) | |
April 2018 Update (17134) | |
Fall Creators Update (16299) | |
Creators Update (15063) |
Device form factor | Saw the problem? |
---|---|
Desktop | Yes |
Xbox | |
Surface Hub | |
IoT |
Additional context
When trying to watch savePicker
, I can see
| Name | Value | Type – | – | – | – ▶ | FileTypeChoices | ‘savePicker.FileTypeChoices’ threw an exception of type ‘System.InvalidCastException’ | System.Collections.Generic.IDictionary<string, System.Collections.Generic.IList<string>> {System.InvalidCastException}
I guees there is something abnormal with savePicker.FileTypeChoices
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
I forgot to say that the demos where updated: https://github.com/microsoft/WinUI-3-Demos/ and I’m no longer see this issue.
Thanks. I’m closing the issue, feel free to reopen it in case I miss something.
@stevenbrix sure, demo samples will be updated. @KiruyaMomochi I will take a look to this issue to see if it repros in the next Preview.