Essentials
Essentials copied to clipboard
[Bug] Launcher in iOS - UTI exception when trying to open file
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
- Run the iOS Sample for Xamarin Essentials
- Select the Launcher option
- 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
- Version with issue:
- Xamarin Essentials: 1.6.1 and 1.7.0
- Windows 10 PC
- MacOS Big Sur Version 11.5.2
- Mac Mono Framework MDK. Runtime: Mono 6.12.0.140 (2020-02/51d876a041e) (64-bit) Package version: 612000140
- Last known good version: N/A
- IDE: Microsoft Visual Studio 2019 Version 16.11.1
- Xamarin: 16.11.000.174 (d16-11@e8f56f1)
- Xamarin.iOS and Xamarin.Mac SDK: 14.20.0.25 (3b53e529b)
- Platform Target Frameworks:
- iOS: 8.0 and 10.0
- Nuget Packages:
- Xamarin Forms: 5.0.0.2012 and 5.0.0.2083
- Xamarin Essentials: 1.6.1 and 1.7.0
- Affected Devices:
- Tested with iPhone 12 Simulator with iOS 14.5
Screenshots
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:
-
Install the MimeTypes Nuget Package (https://www.nuget.org/packages/MimeTypes) in the shared project.
-
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