Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FilePicker on MacOS does not always return the file picked #11088

Closed
ozster123 opened this issue Nov 3, 2022 · 35 comments · Fixed by #13814
Closed

FilePicker on MacOS does not always return the file picked #11088

ozster123 opened this issue Nov 3, 2022 · 35 comments · Fixed by #13814
Labels
area/essentials 🍞 Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info fixed-in-8.0.0-preview.6.8686 Look for this fix in 8.0.0-preview.6.8686! platform/macOS 🍏 macOS / Mac Catalyst t/bug Something isn't working

Comments

@ozster123
Copy link

ozster123 commented Nov 3, 2022

Description

While using FilePicker on MacOS it will regularly return null for the FileResult when a file is chosen. Code below. After a few selects it works. No exceptions or crashes.
Any ideas?

Version 17.4 Preview (17.4 build 2366)
Runtime
.NET 6.0.9 (64-bit)
Architecture: X64

        [RelayCommand]
	private async void SelectFile()
	{
		FileResult result = null;
            try
            {
                FilePickerFileType filePickerFileType = new FilePickerFileType(
                    new Dictionary<DevicePlatform, IEnumerable<string>>{
                    { DevicePlatform.MacCatalyst, new [] { "json" } },
                    { DevicePlatform.macOS, new [] { "json"} },
                    { DevicePlatform.WinUI, new [] { ".json" } }
                    });
                PickOptions pickOptions = new PickOptions
                {
                    PickerTitle = "Choose an engine file.",
                    FileTypes = filePickerFileType
                };

                result = await FilePicker.Default.PickAsync(pickOptions);
            }
            catch (Exception e)
            {
                Console.WriteLine(String.Format("Exception {0}", e.Message));
            }
            if (null != result)
		{
<Button Text="Select..." Command="{Binding SelectFileCommand}"/>

Steps to Reproduce

Create a new .net Maui App
Add a button.
Add a relay command for the button.
Use code above to select a file.

Link to public reproduction project repository

n/a

Version with bug

7.0 Release Candidate 2

Last version that worked well

Unknown/Other

Affected platforms

macOS

Affected platform versions

macOS 12, 13

Did you find any workaround?

No

Relevant log output

+[CATransaction synchronize] called within transaction
@ozster123 ozster123 added the t/bug Something isn't working label Nov 3, 2022
@jsuarezruiz jsuarezruiz added the platform/macOS 🍏 macOS / Mac Catalyst label Nov 3, 2022
@Eilon Eilon added the area/essentials 🍞 Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label Nov 3, 2022
@PureWeen PureWeen added the s/needs-repro Attach a solution or code which reproduces the issue label Nov 3, 2022
@ghost
Copy link

ghost commented Nov 3, 2022

Hi @ozster123. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ozster123
Copy link
Author

I have created a minimal example
https://github.com/ozster123/FilePickerTest.

I switched back to
Visual Studio Community 2022 for Mac
Version 17.3.8 (build 5)

Runtime
.NET 6.0.5 (64-bit)
Architecture: X64

This shows the problem usually first or second select.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Nov 4, 2022
@jfversluis jfversluis removed the s/needs-attention Issue has more information and needs another look label Nov 4, 2022
@jfversluis jfversluis added this to the Backlog milestone Nov 4, 2022
@ghost
Copy link

ghost commented Nov 4, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@jfversluis
Copy link
Member

Thanks for adding the repro!

@Zetthard
Copy link

I have the same issue as #11462, FilePicker.Default.PickAsync always returns null and is not being awaited by caller.
MacOS 13 x64; VS for Mac 2022 17.4 .net SDK 7.0.100; App target platform .net 6; build for MacCatalyst

I tried to use Task.Result instead of await, but it stalls the app and never brings up the file dialog at all.

@datvm
Copy link

datvm commented Nov 24, 2022

Yep, I encountered it as well (see the closed duplicate issue #11574 ). Calling FilePicker.PickMultipleAsync on Mac shows the Open dialog. However before user has anything to do with the dialog, the code jumps to the next instruction right away (my code has await).

@stephenbonar
Copy link

I have a similar issue, although in my case the method doesn't even return null. If I set a breakpoint on a call such as:

var result = await FilePicker.Default.PickAsync();

The code never reaches the next line where I evaluate the result for null. The OS file picker does launch, but after selecting the file, the method has already terminated. No exceptions are generated, and I can see threads starting and stopping in the Application Output. But that's it. If I re-run the method, it works successfully the second time.

@gcadmes-extron
Copy link

Any status updates for this item?
Currently the FilePicker on macOS is unusable.

@MartyIX
Copy link
Collaborator

MartyIX commented Feb 10, 2023

I have hit the same issue. Quite unexpected.

@MartyIX
Copy link
Collaborator

MartyIX commented Feb 10, 2023

Testing with the latest commit of the main branch, it looks to me that it works on macOS in Essentials samples. See:

It would be great if somebody could verify it as well.

@gcadmes-extron
Copy link

gcadmes-extron commented Feb 10, 2023

It seems if I remove all breakpoints and let it run, sometimes the issue doesn't happen. But most of the time, the FilePicker is unusable in its current state.

@MartyIX
Copy link
Collaborator

MartyIX commented Feb 10, 2023

For me it's more like "almost never picks the file and occasionally it does" so time is important. I guess the code does not wait for something.

@datvm
Copy link

datvm commented Feb 10, 2023

I wrote this package to "fix" these problems in the mean time: datvm/LukeMauiFilePicker. Basically I re-implement them on platforms that the official APIs are having trouble with. Also support a Save Picker.

@MartyIX
Copy link
Collaborator

MartyIX commented Feb 10, 2023

@datvm So maybe you can fix the MAUI's macOS implementation for everyone to benefit? :)))

@datvm
Copy link

datvm commented Feb 11, 2023

@MartyIX sure that's a great suggestion, I guess I could try. I have never contributed to MS's repo before though, so I will need to get myself familiar with it. Though I wonder if we do get a PR, how long until they release such a fix?

@MartyIX
Copy link
Collaborator

MartyIX commented Feb 11, 2023

I have never contributed to MS's repo before though, so I will need to get myself familiar with it.

It's just creating a PR really.

Though I wonder if we do get a PR, how long until they release such a fix?

IMO there is no definitive answer to that. I would be hopeful that it would take a month. However, once the fix is merged, one can use it thanks to https://github.com/dotnet/maui/blob/main/.github/DEVELOPMENT.md#testing-branch-against-your-project (I use it quite often for macOS but that's just me).

@MartyIX
Copy link
Collaborator

MartyIX commented Mar 10, 2023

On my macOS Ventura, I can see that this is the culprit:

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

(Deleting the code seems to fix the issue)

The two delegates compete with each other and if this delegate wins, then no file is picked.

@cdavidyoung
Copy link

I am having a similar problem. The FilePicker was working fine on MacOS (as well as the other platforms) but it suddenly stopped working on just this one platform. Hopefully #13814 will fix this. Thanks @MartyIX !

@MartyIX
Copy link
Collaborator

MartyIX commented Mar 11, 2023

@cdavidyoung What is your macOS version please? I wonder if the issue manifests only on the newest macOS releases or whether it affects even older ones.

@cdavidyoung
Copy link

Ventura 13.2.1

@cdavidyoung
Copy link

cdavidyoung commented Mar 12, 2023

I tried it on Monterey 12.6.3 on a 2014 Intel Core i5 Mac Mini as well and FilePicker hangs there as well.

@mattleibow
Copy link
Member

I just tried on Monterey 12.6.3 and it seems to work.

Screenshot 2023-03-17 at 3 51 14 PM

I copied the snippet of code from this issue and no hangs and gets the result.

What happens if you create a blank app and put the code in some button click?

@cdavidyoung
Copy link

I have already tried it on the standard Maui app. When I clicked the button it was able to pick correctly.

As I mentioned before this used to work with my app as well. I think it must be some sort of race condition that makes it stop working in some cases.

@MartyIX
Copy link
Collaborator

MartyIX commented Mar 17, 2023

As I mentioned before this used to work with my app as well. I think it must be some sort of race condition that makes it stop working in some cases.

I have already described the race here.

@MartyIX
Copy link
Collaborator

MartyIX commented Mar 17, 2023

@mattleibow

I just tried on Monterey 12.6.3 and it seems to work.

Is it possible that the bug manifests only on macOS Ventura?

@cdavidyoung
Copy link

I have tried my app on both Ventura and Monterey. The FilePicker hangs in both cases.

@mattleibow
Copy link
Member

mattleibow commented Mar 17, 2023

@cdavidyoung can you attach a sample of this happening? And also the results of dotnet --info and dotnet workload --info?
I am testing this on my mac, but I am assuming something else is different with the SDK and/or something in my test app.

When you say "hang", you mean the await never returns or the app freezes?

@cdavidyoung
Copy link

Hang means in my app it does not return from the call to FilePicker.

I can't provide a sample of this happening because it works fine in the standard Maui app. I wish I could. It only happens in my app.

@mattleibow
Copy link
Member

Do you have any third party things that pop up dialogs? If you move this code to say a blank page in your app does it happen? Or if you swap out the main page in the app for a blank one does it happen?

It clearly is affecting things, but it seems that something else may be breaking us. We can see about the PR, but that may hide other issues.

@MartyIX
Copy link
Collaborator

MartyIX commented Mar 21, 2023

Not a question for me but ...

Do you have any third party things that pop up dialogs?

I don't use any 3rd party things. I have a pure MAUI application and on mac arm64 Ventura, the issue is very easy to reproduce as the bug manifests almost always (say 4 times out of 5 attempts). So that might be an easy thing to try.

@cdavidyoung
Copy link

cdavidyoung commented Mar 27, 2023

As another data point, I just recreated my project from scratch starting with the standard Maui app. I then copied and merged all my project files. This fixed the FilePicker problem that I was having with the Mac version. It runs perfectly on my Mac except that there is some kind of provisioning problem when I try to upload the release version to the App Store.

So, if you are having a problem with the FilePicker recreating your project from scratch may fix it. CacheAll is the name of the app if you want to check it out for Android (Galaxy Store), iOS, and Windows.

@bartimusprimed
Copy link

Well after like an hour of me thinking I am stupid and doing something wrong, I can confirm I have this issue as well. Running the file picker twice will result it in running the second time. Seems like the first delegate is hanging as mentioned by @MartyIX

@LukeFranky
Copy link

Same thing is happening on iOS 16.1.1 & VS 2022 17.6.1. Sometimes selecting a file works, sometimes it doesn't (returns null).

Super frustrating.

@samhouts samhouts modified the milestones: Backlog, .NET 8 Planning, .NET 8 Jul 10, 2023
@samhouts samhouts added the fixed-in-8.0.0-preview.6.8686 Look for this fix in 8.0.0-preview.6.8686! label Jul 11, 2023
@brightertools
Copy link

I also have this issue on MacOS, it works in dev, but not when deployed via TestFlight.. works fine on windows and after deployed via the Windows store.

Is there a definitive fix for this?

@ghost
Copy link

ghost commented Jul 31, 2023

Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you!

@dotnet dotnet locked as resolved and limited conversation to collaborators Sep 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/essentials 🍞 Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info fixed-in-8.0.0-preview.6.8686 Look for this fix in 8.0.0-preview.6.8686! platform/macOS 🍏 macOS / Mac Catalyst t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.