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

FilePicker Plugin for Xamarin and Windows
MIT License
157 stars 80 forks source link

Error : Input string was not in a correct format #148

Closed ralpholazo24 closed 5 years ago

ralpholazo24 commented 5 years ago

Expected Behavior

Pick a file from download folder. But aside in download folder, I can choose files in different folders.

Actual Behavior

It throws an error "Input string was not in a correct format."

Here is my code: fileData = await CrossFilePicker.Current.PickFile(); if (fileData == null) return;

I also have the permission to read and write in storage. Does someone also encounter this error?

jfversluis commented 5 years ago

Could you update to the latest version and see if the issue still exists?

vividos commented 5 years ago

Also, the whole output from ex.ToString() world be interesting!

ralpholazo24 commented 5 years ago

Could you update to the latest version and see if the issue still exists?

It stills throw the error. I already update it to Xamarin.Plugin.FilePicker -Version 2.1.34

This is only happens when I pick a file from download folder. I already try it to the other devices, and it still gives me that error.

ralpholazo24 commented 5 years ago

Also, the whole output from ex.ToString() world be interesting!

2019-09-20_6-55-19

at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x0004d] in /Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/number.cs:1074 at System.Number.ParseInt64 (System.String value, System.Globalization.NumberStyles options, System.Globalization.NumberFormatInfo numfmt) [0x00014] in /Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/number.cs:766 at System.Int64.Parse (System.String s) [0x00000] in /Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/int64.cs:114 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 --- at Plugin.FilePicker.FilePickerImplementation+d__4.MoveNext () [0x00028] in D:\a\1\s\src\Plugin.FilePicker\Android\FilePickerImplementation.android.cs:60 --- End of stack trace from previous location where exception was thrown --- at EbookApp.Import+d__3.MoveNext () [0x00035] in D:\SourceCode\EBookApp\EbookApp\EbookApp\Import.xaml.cs:45

vividos commented 5 years ago

Could you try out the sample project in this repository, set a breakpoint at Plugin.FilePicker.IOUtil.GetPath() where the long value is parsed and tell us the Uri and the I'd that the code wants to parse? Thanks!

ralpholazo24 commented 5 years ago

So here is what I've notice on the code.

  1. My DocumentsContract.GetDocumentId(uri) is starts with msf: thats why upon long.parse it gets error.

image

image

ralpholazo24 commented 5 years ago

@vividos any updates?

vividos commented 5 years ago

I looked at the images, and it seems the code that parses content URIs from DocumentsContract doesn't recognize all variants of URIs that can occur. I always thought that the code is brittle, as it assumed how URIs are constructed. The best way to fix this would be to replace long.Parse with TryParse and just return null when it doesn't parse. If you can come up with a PR, we're happy to incorporate it into FilePicker plugin. After all, the plugin is open source! I have limited time at the moment. Sorry!

ralpholazo24 commented 5 years ago

Sounds good. Sure, I will try it and have a PR for it.

mayank1214 commented 5 years ago

@ralpholazo24 and @vividos I am having same issue. Any timeline to fix this? I would be happy to create a PR.

vividos commented 5 years ago

@mayank1214 if you have time to fix this, why not! The task should be simple: Replace the long.Parse() call with a long.TryParse() call and return null when the parsing failed. Returning null from that function ensures that the original content:// URL is returned. In this case the caller must use GetStream() to access the picked data, as it's the only way.

mayank1214 commented 5 years ago

@vividos Here is the PR request . I am new to Xamarin and this my first project. I encountered a weird issue while working on this PR and hoping someone can help me to figure out the answer. My local variables were not displaying values on debug watcher. Any idea why? See below screenshot

LocalVariables

I was also getting "System.FormatException: 'Input string was not in a correct format.' inconsistently. I had purposely set CLR Exception to get more information about that error.

FormatException

vividos commented 4 years ago

Note: Fixed in version 2.1.36-beta.