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

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

OpenFile on Android Method 'string.Split' not found. #144

Closed xXxTheDarkprogramerxXx closed 4 years ago

xXxTheDarkprogramerxXx commented 5 years ago

Expected Behavior

FileData fileData = await CrossFilePicker.Current.PickFile(); should Poplate FileData with some information

Actual Behavior

Results in the following exception

Method 'string.Split' not found.

System.MissingMethodException: Method 'string.Split' not found. at Plugin.FilePicker.FilePickerActivity.OnActivityResult (System.Int32 requestCode, Android.App.Result resultCode, Android.Content.Intent data) [0x0003c] in D:\a\1\s\src\Plugin.FilePicker\Android\FilePickerActivity.android.cs:147

Steps to Reproduce the Problem

  1. try { FileData fileData = await CrossFilePicker.Current.PickFile(); if (fileData == null) return; // user canceled file picking

                string fileName = fileData.FileName;
                string contents = System.Text.Encoding.UTF8.GetString(fileData.DataArray);
    
                System.Console.WriteLine("File name chosen: " + fileName);
                System.Console.WriteLine("File data: " + contents);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("Exception choosing file: " + ex.ToString());
            }

Specifications

xXxTheDarkprogramerxXx commented 5 years ago

So I'm not sure why this is happening at all

I added the solution .csproj to my solution deleted everything except the android implantation and it works fine now

kamihubber commented 5 years ago

i have same problem here on android 5,6 and 9.

this is my code :

try { var file = await CrossFilePicker.Current.PickFile();

            if ( file != null)
            {
                image = file.DataArray;

                xQuizImage.Source = get_imagesource_from_byte(image);

                if (file != null)
                {
                    xImageNameLB.Text = file.FileName;
                }
            }               

        }
        catch (Exception ex)
        {
            var ss = ex.Message;
            var ss2 = ex.Message;                
        }

the file picking view comes up but after i choose the file i get an exception :

{System.MissingMethodException: string[] string.Split(char,System.StringSplitOptions) at Plugin.FilePicker.FilePickerActivity.OnActivityResult (System.Int32 requestCode, Android.App.Result resultCode, Android.Content.Intent data) [0x0003c] in D:\a\1\s\src\Plugin.FilePicker\Android\FilePickerActivity.android.cs:147 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <43dbbdc147f2482093d8409abb04c233>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <43dbbdc147f2482093d8409abb04c233>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <43dbbdc147f2482093d8409abb04c233>:0 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in <43dbbdc147f2482093d8409abb04c233>:0 at Plugin.FilePicker.FilePickerImplementation+<PickFile>d__4.MoveNext () [0x0002b] 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 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <43dbbdc147f2482093d8409abb04c233>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <43dbbdc147f2482093d8409abb04c233>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <43dbbdc147f2482093d8409abb04c233>:0 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult ()

kamihubber commented 5 years ago

also i use nuget package version 2.1.18 , visual studio 2017 , .netstandard 2.0.3 .

vividos commented 5 years ago

Could you try it the latest beta version 2.1.32-beta? There was a bug that the plugin was built in Debug while the app was in release. Might be related.

kamihubber commented 5 years ago

well i just tried it with two different nuget versions :

with 2.1.32-beta in debug mode of my project i got same (string.split) exception and in release mode i got this :

(Severity Code Description Project File Line Suppression State Error The "LinkAssemblies" task failed unexpectedly. Mono.Linker.MarkException: Error processing method: 'System.String Plugin.FilePicker.IOUtil::GetPath(Android.Content.Context,Android.Net.Uri)' in assembly: 'Plugin.FilePicker.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.String[] System.String::Split(System.Char,System.StringSplitOptions) at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference) at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference) at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction) at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body) at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method) at Mono.Linker.Steps.MarkStep.ProcessQueue() --- End of inner exception stack trace --- at Mono.Linker.Steps.MarkStep.ProcessQueue() at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue() at Mono.Linker.Steps.MarkStep.Process() at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context) at Mono.Linker.Pipeline.Process(LinkContext context) at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context) at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.LinkAssemblies.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() Sidma_Studnet_App.Android )

just before deploying. . . .

but with nuget version 2.0.135 it worked completely right in both debug and release mode.the files are shown and choosed properly.

hope this helps.

vividos commented 5 years ago

What Android framework version do you have in the Android project? FilePicker supports 6.0 to 9.0. Maybe that's the reason

xXxTheDarkprogramerxXx commented 5 years ago

I did this on android 8.1 to 9 as well I did however use the code as is in my test application https://github.com/xXxTheDarkprogramerxXx/Store-Remote-Tool-Android

vividos commented 5 years ago

I meant the TargetFrameworkVersion, but I see it's on v9.0, so this should be ok. I will try out your project and see if I can reproduce the error.

jfversluis commented 4 years ago

Closing this since this project will retire, please check out Xamarin.Essentials which now has a FilePicker based on this one.