dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.01k stars 1.72k forks source link

Mediapicker API is inconsistent across platforms on cancellation #18889

Open ErisApps opened 10 months ago

ErisApps commented 10 months ago

Description

Due to the behavior not being documented in XML docs in regards of what happens when the user cancels picking/taking a picture or video, I started doing some digging through the source code

My initial use case is a Xamarin.Android app (running on .NET 7 for the time being) that has NRT enabled. At first, I thought that MediaPicker methods would result in an exception due to the shared class having #nullable enable at the top, but the methods themselves having Task<FileResult> as return type opposed to Task<FileResult?>, letting the tooling in the IDE also indicate that null-checks are not needed.

And... that guess was right... but seemingly not across all platforms. Tizen, iOS (and possibly MacOS) do indeed throw an exception (most likely TaskCancelledException), however... Android and UWP do just return null instead.

Steps to Reproduce

  1. Use the MediaPicker API on any platform (eg; Android and iOS)
  2. Cancel the picker
  3. Observe the result

Link to public reproduction project repository

I'll provide one in the upcoming days and will edit this section.

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows, macOS, Other (Tizen, Linux, etc. not supported by Microsoft directly)

Affected platform versions

Not applicable, it's an issue with the API implementation.

Did you find any workaround?

Both catching the exception and null-checking seems to do the trick in the cross-platform code, but I'd rather see a singular consistent approach.

Relevant log output

No response

ghost commented 10 months ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.