Skip to content

FilePicker.PickAsync Task Hangs When User Swipes Down to Cancel the Picker #30282

Open
@git103

Description

@git103

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

  1. Create a new MAUI app with MAUI version 9.0.80.
  2. 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}");
}
  1. Run the app.
  2. Click the button to open the file picker.
  3. 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

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-essentials-filepickerpotential-regressionThis issue described a possible regression on a currently supported version., verification pendingt/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions