Skip to content

FilePicker PickMultipleAsync nullable reference type #33114

@aalsamoht

Description

@aalsamoht

Description

FilePicker.PickMultipleAsync() can return null.
The method declaration is Task<IEnumerable<FileResult?>> PickMultipleAsync(PickOptions? options = null);, but it should be Task<IEnumerable<FileResult>?> PickMultipleAsync(PickOptions? options = null);

The IEnumerable should be nullable, not the FileResult.

https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.storage.filepicker.pickmultipleasync?view=net-maui-10.0

See issue #27710

Steps to Reproduce

var fileResults = await filePicker.PickMultipleAsync(PickOptions.Default);

// Warning: Expression is always true according to nullable reference types' annotations
if (fileResults is not null)
{
    foreach (var fileResult in fileResults)
    {
        // Dereference of a possibly null reference
        Console.WriteLine(fileResult.FileName);
    }
}

Link to public reproduction project repository

No response

Version with bug

10.0.20

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

No response

Affected platforms

iOS, Android, I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions