maui: FilePicker on MacOS does not always return the file picked
Description
While using FilePicker on MacOS it will regularly return null for the FileResult when a file is chosen. Code below. After a few selects it works. No exceptions or crashes. Any ideas?
Version 17.4 Preview (17.4 build 2366) Runtime .NET 6.0.9 (64-bit) Architecture: X64
[RelayCommand]
private async void SelectFile()
{
FileResult result = null;
try
{
FilePickerFileType filePickerFileType = new FilePickerFileType(
new Dictionary<DevicePlatform, IEnumerable<string>>{
{ DevicePlatform.MacCatalyst, new [] { "json" } },
{ DevicePlatform.macOS, new [] { "json"} },
{ DevicePlatform.WinUI, new [] { ".json" } }
});
PickOptions pickOptions = new PickOptions
{
PickerTitle = "Choose an engine file.",
FileTypes = filePickerFileType
};
result = await FilePicker.Default.PickAsync(pickOptions);
}
catch (Exception e)
{
Console.WriteLine(String.Format("Exception {0}", e.Message));
}
if (null != result)
{
<Button Text="Select..." Command="{Binding SelectFileCommand}"/>
Steps to Reproduce
Create a new .net Maui App Add a button. Add a relay command for the button. Use code above to select a file.
Link to public reproduction project repository
n/a
Version with bug
7.0 Release Candidate 2
Last version that worked well
Unknown/Other
Affected platforms
macOS
Affected platform versions
macOS 12, 13
Did you find any workaround?
No
Relevant log output
+[CATransaction synchronize] called within transaction
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 35 (4 by maintainers)
Hang means in my app it does not return from the call to FilePicker.
I can’t provide a sample of this happening because it works fine in the standard Maui app. I wish I could. It only happens in my app.
I have tried my app on both Ventura and Monterey. The FilePicker hangs in both cases.
Ventura 13.2.1
I wrote this package to “fix” these problems in the mean time: datvm/LukeMauiFilePicker. Basically I re-implement them on platforms that the official APIs are having trouble with. Also support a Save Picker.