Essentials
Essentials copied to clipboard
[Bug] FilePicker.PickAsync() returns random results
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)
- use FilePicker.PickAsync() on iOS
- pick a file by tapping one
- (dialog closes)
Expected Behavior
PickAsync returns a FileResult.
Actual Behavior
PickAsync returns in most cases null.
Basic Information
- Version with issue: 1.7.1, 1.7.2, 1.7.3
- Last known good version: 1.7.0
- IDE: VS 17.3 Pre 1.1
- Platform Target Frameworks:
- iOS: 15.5 (physical device iPad Pro 12,9, attached to Mac but also in Release as custom app with App Store)
- Android: (not in active development)
- UWP: -