jfversluis/FilePicker-Plugin-for-Xamarin-and-Windows

Android 10 Downloads File Select Error

Closed this issue · 9 comments

Expected Behavior

Select a PDF File

Actual Behavior

Throws Exception as below using API 29. Works fine selecting Images. Works fine selecting PDF on Android 9 API 28.

##Code Example
fileTypes = new string[] { "application/pdf", "image/*" };
SelectedFile = await CrossFilePicker.Current.PickFile(fileTypes);

Choosing a PDF File throws this error:
FilePicker Exception:::::
System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) [0x0001a] in :0
at System.Number.ParseInt64 (System.ReadOnlySpan`1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) [0x00016] in :0
at System.Int64.Parse (System.String s) [0x00016] in :0
at Plugin.FilePicker.IOUtil.GetPath (Android.Content.Context context, Android.Net.Uri uri) [0x000b0] in <8283f9c30b1b41b2a46dd45643b296cd>:0
at Plugin.FilePicker.FilePickerActivity.OnActivityResult (System.Int32 requestCode, Android.App.Result resultCode, Android.Content.Intent data) [0x00039] in <8283f9c30b1b41b2a46dd45643b296cd>:0
--- End of stack trace from previous location where exception was thrown ---

at Plugin.FilePicker.FilePickerImplementation.PickFile (System.String[] allowedTypes) [0x0006d] in <8283f9c30b1b41b2a46dd45643b296cd>:0
at LakelandMobileApp.AddInsurancePage.OpenFileBtn_Clicked (System.Object sender, System.EventArgs e) [0x001c3] in <3ebb4a31181c42a7b173cdc4b26bc59a>:0

Specifications

  • NuGet package version: 2.1.34
  • Platform(s): Android API 29

I think this is a duplicate of #148 that has the exact same stack trace. The bug should be fixed in the 2.1.36-beta NuGet package (you have to check "Include prerelease" to see that version).

I updated the package to 2.1.36-beta cleaned and rebuilt app and I still get the following error with any filetype in the downloads folder in Android 10. Android 9 works ok.

FilePicker Exception:::::
System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) [0x0001a] in <9a7f37f8b53d493eb264b2e0d3b2956a>:0
at System.Number.ParseInt64 (System.ReadOnlySpan`1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) [0x00016] in <9a7f37f8b53d493eb264b2e0d3b2956a>:0
at System.Int64.Parse (System.String s) [0x00016] in <9a7f37f8b53d493eb264b2e0d3b2956a>:0
at Plugin.FilePicker.IOUtil.GetPath (Android.Content.Context context, Android.Net.Uri uri) [0x000b0] in <8283f9c30b1b41b2a46dd45643b296cd>:0
at Plugin.FilePicker.FilePickerActivity.OnActivityResult (System.Int32 requestCode, Android.App.Result resultCode, Android.Content.Intent data) [0x00039] in <8283f9c30b1b41b2a46dd45643b296cd>:0
--- End of stack trace from previous location where exception was thrown ---

at Plugin.FilePicker.FilePickerImplementation.PickFile (System.String[] allowedTypes) [0x0006d] in <8283f9c30b1b41b2a46dd45643b296cd>:0
at MobileApp.AddInsurancePage.OpenFileBtn_Clicked (System.Object sender, System.EventArgs e) [0x001c3] in :0

Could you please check if you're really referencing 2.1.36-beta? In that version we replaced the Parse() call that occurs in the call stack with a TryParse() call, so it seems you picked up a previous version. Did you do a full rebuild?

I have Removed FilePicker Package from Dependencies. Cleaned the Application. Re-Added the FilePicker Package to Dependencies and Rebuilt the application. I removed the installation from the devices and re-installed and still get the same error. Not sure if there is any other way to verify the package?

Screen Shot 2020-02-28 at 12 42 08 PM

Hmm that's strange. Still the same stack trace from above? You could peek into your NuGet cache folder and check for the Plugin.FilePicker.dll in the iOS subfolder, then open it with ILSpy or similar tools. The tool should properly decompile the assembly and you could check the code in IOUtil.GetPath(). Since you're on a Mac, I don't know exactly where that NuGet cache folder is.

Yes it looks to be that VS is using the 2.1.34 Package. But for the life of me I can not get it to use the 2.1.36-beta. I have even removed every reference in the app to FilePicker, remove all of the Nuget downloads (From Solution and Cache) and it is still asking for a 2.1.34 reference and I can not find anywhere it is being referred to. So frustrating.

ask "ResolveNuGetPackageAssets"
/Library/Frameworks/Mono.framework/Versions/6.6.0/lib/mono/xbuild/Microsoft/NuGet/Microsoft.NuGet.targets(186,5): error : The package Xamarin.Plugin.FilePicker with version 2.1.34 could not be found in /Users/collin/.nuget/packages/. Run a NuGet package restore to download the package.
Done executing task "ResolveNuGetPackageAssets" -- FAILED.

Yes, sometimes Visual Studio for Mac doesn't know that it should do a restore. I usually do a VS restart, then a restart of the Mac and hope it works again after that.

Ya I can't figure out the issue with Visual Studio. I've remove every reference to FilePicker from the laptop, solution, config files and ever other file I could search., and It is still asking for it. I re-created the Android version of the app on a Windows PC, and using the 2.1.36-beta the program does work, therefore I'll close this as it is a VS issue and not an issue with the plugin. Thanks for your assistance!

You're welcome!