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 506 forks source link

[Bug] Launcher in iOS - UTI exception when trying to open file #1877

Open tilemmpon opened 3 years ago

tilemmpon commented 3 years ago

Description

When trying to open any file with Xamarin Essentials Launcher in iOS I receive the error "System.ArgumentNullException: 'Value cannot be null. Parameter name: uti' ". I attach relative screenshot. The code I am using is as per documentation:

await Launcher.OpenAsync(new OpenFileRequest
{
    File = new ReadOnlyFile(file)
});

And the error appears in my application, in an empty new application with only this code, and also when running the Xamarin Essentials Samples. The Android version works fine. I have tracked the error down to this line:

https://github.com/xamarin/Essentials/blob/7218ab88f7fbe00ec3379bd54e6c0ce35ffc0c22/Xamarin.Essentials/FileSystem/FileSystem.ios.tvos.watchos.macos.cs#L56

where the "conformingToUti" string parameter is passed as null.

Verification that this error can be reproduced by other users as well is needed.

Steps to Reproduce

  1. Run the iOS Sample for Xamarin Essentials
  2. Select the Launcher option
  3. Give a filename and file contents and click "Open File"

Expected Behavior

The file should open with default app or shown as preview.

Actual Behavior

The application throws an exception ("System.ArgumentNullException: 'Value cannot be null. Parameter name: uti' ").

Basic Information

Screenshots

image

tilemmpon commented 2 years ago

To further update on this issue, this seems to be an error when running on iOS Simulator on Mac Silicon. With a real device it works without any crash (*). For the simulator I found the following workaround if someone has the same issue and wants to test the launcher on Mac Silicon:

  1. Install the MimeTypes Nuget Package (https://www.nuget.org/packages/MimeTypes) in the shared project.
  2. Use the package to detect the mine type and input it in the launcher, like this:

                    var mime = MimeTypes.GetMimeType(<filePath>);
                    await Launcher.OpenAsync(new OpenFileRequest
                    {
                        File = new ReadOnlyFile(<filePath>, mime)
                    });

(*) although we still have the issue reported in https://github.com/xamarin/Essentials/issues/1376 which is supposedly fixed