Skip to content

FilePicker.PickAsync Task Hangs When User Cancels the Picker in iOS #29490

@tharindup

Description

@tharindup

Description

When using FilePicker.PickAsync in a .NET MAUI application, if the user cancels the file picker (either by using "Cancel" button or swiping down the picker), 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.

Steps to Reproduce

  1. Create a new MAUI app.
  2. Update the following code on MainPage.xaml.cs
// 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}");
}

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 button tap.

Link to public reproduction project repository

https://github.com/tharindup/FilePickerCancelBug

Version with bug

9.0.70 SR7

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

No response

Did you find any workaround?

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-essentials-filepickeri/regressionThis issue described a confirmed regression on a currently supported versionregressed-in-9.0.50s/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions