Description
Description
When using FilePicker.PickAsync in a .NET MAUI application, if the user cancels the file picker by swiping to close, the task does not complete and remains in a hanging state. This behavior prevents proper handling of cancellation and leaves tasks in an incomplete state.
This issue occurs specifically when the user cancels the picker by swiping to close. The cancel button works correctly and the issue also does not occur when a file is successfully picked.
This issue only seems to affects older iOS versions, so devices < iOS 16.
Steps to Reproduce
- Create a new MAUI app with MAUI version 9.0.80.
- Update the following code into MainPage.xaml.cs.
private readonly List<Task<FileResult?>> _tasks = [];
private async void CounterBtn_Clicked(object sender, EventArgs e)
{
var completedTasks = _tasks.Where(t => t.IsCompleted).Count();
var inProgressTasks = _tasks.Where(t => !t.IsCompleted).Count();
Console.WriteLine($"Picked tasks: {completedTasks}, Hanging tasks: {inProgressTasks}");
var fileResultTask = FilePicker.PickAsync(new PickOptions
{
PickerTitle = "Please select a file"
});
_tasks.Add(fileResultTask);
var fileResult = await fileResultTask;
if (fileResult == null)
{
Console.WriteLine("No file selected");
return;
}
Console.WriteLine($"Selected file name: {fileResult.FileName}");
}
- Run the app.
- Click the button to open the file picker.
- Cancel the file picker without selecting a file (by swiping down to close the picker).
Expected behavior when user cancels the picker: Hanging tasks should be 0.
Actual behavior when user cancels the picker: Hanging tasks count keeps growing for each cancel attempt.
Link to public reproduction project repository
https://github.com/git103/FilePickerHang
Version with bug
Unknown/Other
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
9.0.40 SR4
Affected platforms
iOS
Affected platform versions
iOS < 16
Did you find any workaround?
No response