0

I am trying to pick a file using the following code

                            FileData fileData = new FileData();

                            fileData = await CrossFilePicker.Current.PickFile();

                            if (fileData != null)

and getting the following exception

  at System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overfl

owResourceKey) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/shared/System/Number.Parsing.cs:1781 
  at System.Number.ParseInt64 (System.ReadOnlySpan`1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) [0x00016] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/shared/System/Number.Parsing.cs:246 
  at System.Int64.Parse (System.String s) [0x0000a] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Int64.cs:106 
  at Plugin.FilePicker.IOUtil.GetPath (Android.Content.Context context, Android.Net.Uri uri) [0x000ab] in D:\a\1\s\src\Plugin.FilePicker\Android\IOUtil.android.cs:64 
  at Plugin.FilePicker.FilePickerActivity.OnActivityResult (System.Int32 requestCode, Android.App.Result resultCode, Android.Content.Intent data) [0x00039] in D:\a\1\s\src\Plugin.FilePicker\Android\FilePickerActivity.android.cs:151 
--- End of stack trace from previous location where exception was thrown ---

and the exception message saying "Input string was not in a correct format".

I am trying it for so long, but unable to find the solution.

Android version - 10

sahithi
  • 1,039
  • 2
  • 14
  • 37
  • 1
    please do NOT post code or errors as images – Jason Dec 19 '20 at 17:40
  • Try to use [Xamarin.Essentials: File Picker](https://learn.microsoft.com/en-us/xamarin/essentials/file-picker?context=xamarin%2Fandroid&tabs=android). – nevermore Dec 21 '20 at 07:48
  • I am using the latest stable version for Xamarin.Essentials but FilePickerAsync() is not accessible. – sahithi Dec 21 '20 at 11:23
  • Does my solution work for you? If yes, can you please accept it (click the ☑️ in the upper left corner of this answer ) so that we can help more people with same problem:). – nevermore Dec 23 '20 at 06:06
  • Done @JackHua-MSFT, Thank you – sahithi Dec 30 '20 at 04:37

1 Answers1

0

I am using the latest stable version for Xamarin.Essentials but FilePickerAsync() is not accessible.

In the latest version for Xamarin.Essentials, to get :

using Xamarin.Essentials;

public async void getFile()
{
    var result = await FilePicker.PickAsync();

    //...
}

The ReadExternalStorage permission is required:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Refer: Xamarin.Essentials: File Picker

nevermore
  • 15,432
  • 1
  • 12
  • 30