exception error using Plugin.Geolocator in xamarin

zkillxkillzkillxkill Member

I want to do a simple app that brings me my current location, I am using Geolocator plug in to consult my location but it throw me an exception error when i call the method GetPositionAsync(), the app have permission to access location in my phone. there is my code:
`try
{

        if ( locator.IsGeolocationEnabled == false )
        {
            await App.Current.MainPage.DisplayAlert("Error", "location is not enable", "aceptar");
            return;
        }
        if( locator.IsGeolocationAvailable == false)
        {
            await App.Current.MainPage.DisplayAlert("Error", "location is not aviable", "aceptar");
            return;
        }
       position = await locator.GetLastKnownLocationAsync();

            if (position == null)
            {
                await App.Current.MainPage.DisplayAlert("Error", "position is not aviable", "Acept");
                return;
            }

        var position = await locator.GetPositionAsync(TimeSpan.MaxValue);
        GeoPos = position.Latitude.ToString();

    }
    catch (Exception ex)
    {
        await App.Current.MainPage.DisplayAlert("Error", ex.ToString(), "aceptar");
    }`

its send me a ca exception and display this error:

"System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.\n at (wrapper stelemref) System.Object:virt_stelemref_object (intptr,object)\n at <StartupCode$NInterpret-Xamarin-Droid>[email protected] (NInterpret.Interpreter this, System.Collections.Generic.Stack1[T] callStack, System.Object x) [0x00029] in <5a7d38ec7eef0f2aa7450383ec387d5a>:0 \n at NInterpret.Interpreter.interpretBlock (System.Object[] args, System.Object[] locals, Mono.Cecil.Cil.Instruction initialInstruction, Microsoft.FSharp.Collections.FSharpSet1[T] inTries, Microsoft.FSharp.Core.FSharpOption1[T] lastException) [0x00225] in <5a7d38ec7eef0f2aa7450383ec387d5a>:0 \n at NInterpret.Interpreter.interpret (System.Object[] args) [0x00099] in <5a7d38ec7eef0f2aa7450383ec387d5a>:0 \n at NInterpret.Interpreter.callAMethod (NInterpret.AMethod m, NInterpret.AType[] ptypes, NInterpret.AType[] genericMethodArgs, System.Collections.Generic.Dictionary2[TKey,TValue] genericArgsIndex, System.Object[] args, System.Collections.Generic.List1[T] byRefArgs, Microsoft.FSharp.Core.FSharpOption1[T] byRefTarget, System.Object target, System.Boolean virtualCall) [0x00184] in <5a7d38ec7eef0f2aa7450383ec387d5a>:0 \n at NInterpret.Interpreter.NInterpret-IInterpreter-TryCall (System.Object o, NInterpret.InterpretedTypeInfo i, System.String n, System.Type[] p, System.Object[] a, System.Type[] ma) [0x001b1] in <5a7d38ec7eef0f2aa7450383ec387d5a>:0 \n at InterpretedSystem.Runtime.CompilerServices.IAsyncStateMachineVT.I (System.String n, System.Type[] p, System.Object[] a, System.Type[] ma) [0x0004c] in <5a7d38ec7eef0f2aa7450383ec387d5a>:0 \n at InterpretedSystem.Runtime.CompilerServices.IAsyncStateMachineVT.System-Runtime-CompilerServices-IAsyncStateMachine-MoveNext () [0x00020] in <5a7d38ec7eef0f2aa7450383ec387d5a>:0 \n at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].Start[TStateMachine] (TStateMachine& stateMachine) [0x0002c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 \n at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke
...
...

tank you all for your time

Answers

  • Me too

    {System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Object of type 'NInterpret.InterpretedObject' cannot be converted to type 'Android.Locations.ILocationListener'.
    at System.RuntimeType.CheckValue (System.Object value, System.Reflection.Binder binder, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00071] in :0
    at System.Reflection.MonoMethod.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00069] in :0
    at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00011] in :0
    at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in :0
    at NInterpret.Interpreter.callAMethod (NInterpret.AMethod m, NInterpret.AType[] ptypes, NInterpret.AType[] genericMethodArgs, System.Collections.Generic.Dictionary2[TKey,TValue] genericArgsIndex, System.Object[] args, System.Collections.Generic.List1[T] byRefArgs, Microsoft.FSharp.Core.FSharpOption1[T] byRefTarget, System.Object target, System.Boolean virtualCall) [0x003f8] in <5b4cad727eef0f2aa745038372ad4c5b>:0 at NInterpret.Interpreter.callMethodReference (System.Collections.Generic.Dictionary2[TKey,TValue] gargs, Mono.Cecil.MethodReference ms, System.Boolean virtualCall) [0x00383] in <5b4cad727eef0f2aa745038372ad4c5b>:0
    at NInterpret.Interpreter.interpretBlock (System.Object[] args, System.Object[] locals, Mono.Cecil.Cil.Instruction initialInstruction, Microsoft.FSharp.Collections.FSharpSet1[T] inTries, Microsoft.FSharp.Core.FSharpOption1[T] lastException) [0x03c71] in <5b4cad727eef0f2aa745038372ad4c5b>:0
    at NInterpret.Interpreter.interpretBlock (System.Object[] args, System.Object[] locals, Mono.Cecil.Cil.Instruction initialInstruction, Microsoft.FSharp.Collections.FSharpSet1[T] inTries, Microsoft.FSharp.Core.FSharpOption1[T] lastException) [0x0013b] in <5b4cad727eef0f2aa745038372ad4c5b>:0
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in :0
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0
    at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 --- End of inner exception stack trace --- at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0004b] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at NInterpret.Interpreter.callAMethod (NInterpret.AMethod m, NInterpret.AType[] ptypes, NInterpret.AType[] genericMethodArgs, System.Collections.Generic.Dictionary2[TKey,TValue] genericArgsIndex, System.Object[] args, System.Collections.Generic.List1[T] byRefArgs, Microsoft.FSharp.Core.FSharpOption1[T] byRefTarget, System.Object target, System.Boolean virtualCall) [0x0049c] in <5b4cad727eef0f2aa745038372ad4c5b>:0
    at NInterpret.Interpreter.callMethodReference (System.Collections.Generic.Dictionary2[TKey,TValue] gargs, Mono.Cecil.MethodReference ms, System.Boolean virtualCall) [0x00383] in <5b4cad727eef0f2aa745038372ad4c5b>:0 at NInterpret.Interpreter.interpretBlock (System.Object[] args, System.Object[] locals, Mono.Cecil.Cil.Instruction initialInstruction, Microsoft.FSharp.Collections.FSharpSet1[T] inTries, Microsoft.FSharp.Core.FSharpOption1[T] lastException) [0x00fba] in <5b4cad727eef0f2aa745038372ad4c5b>:0 at NInterpret.Interpreter.interpretBlock (System.Object[] args, System.Object[] locals, Mono.Cecil.Cil.Instruction initialInstruction, Microsoft.FSharp.Collections.FSharpSet1[T] inTries, Microsoft.FSharp.Core.FSharpOption`1[T] lastException) [0x0013b] in <5b4cad727eef0f2aa745038372ad4c5b>:0 }

Sign In or Register to comment.