xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.52k stars 505 forks source link

[Bug] FilePicker.PickAsync() returns random results #2025

Closed formerlymisterhenson closed 8 months ago

formerlymisterhenson commented 2 years ago

Description

Whilst I was using FilePicker.PickAsync() in <= 1.7.0 with no problems, our users reported in our current (Xamarin Forms) app release, that the FilePicker is not working anymore (for us). I was able to reproduce that, without Exceptions or permission problems. The problem is, that in about 4 of 5 cases PickAsync returns null instead of the file result.

Well, there are not that many things where you could go wrong, I guess:

try
{
    //Device.BeginInvokeOnMainThread(async () => // did not matter here
    {
        var result = await FilePicker.PickAsync();

        if (result != null) // only 1 in 5 cases
        {
            using var stream = await result.OpenReadAsync();
            ...
        }
    } 
    //);
}
catch (Exception e)
{
    // does not happen
    Log.Error($"blah {e}");
}

I was trying to understand what's the problem here and had a look at: https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/FilePicker/FilePicker.ios.cs

I think there is something suspicious about that DismissHandler thing introduced with https://github.com/xamarin/Essentials/pull/1846

documentPicker.PresentationController.Delegate = new Platform.UIPresentationControllerDelegate
{
    DismissHandler = () => GetFileResults(null, tcs)
};

So I reverted Essentials to 1.7.0 and it did work fine again. Upgrading to 1.7.1, 1.7.2, 1.7.3 it does not work (reproducible for me).

Steps to Reproduce (I guess)

  1. use FilePicker.PickAsync() on iOS
  2. pick a file by tapping one
  3. (dialog closes)

Expected Behavior

PickAsync returns a FileResult.

Actual Behavior

PickAsync returns in most cases null.

Basic Information

formerlymisterhenson commented 9 months ago

Would be nice, if someone could have a look in this issue after 1,5 years? I do see this is (now) legacy old Xamarin, but with the all showstopper-ish severity bugs still occuring in MAUI (sorry) I am very pessimistic about the health concerning the whole ecosystem (or whatsoever). As the guy suggesting to create our corporate app with Xamarin, after three years I feel a bit embarrassed. Ok I'll stop whining.