Exception In Xamarin Forms and Visual Studio - An unhandled exception occured

I'm developing an application in Xamarin Forms with Visual Studio 2017. So far I have not faced any major issues, but now when I debug my application on the Android device, it always returns an exception that is not detected by try / catch. There is not much information in the IDE about the fact, other than these: 1 - An unhandled exception occured. 2 - The selected debug mechanism does not support any code running on the current thread (eg only the native runtime code is running) The error always occurs when I try to navigate to a registration confirmation screen where the user needs to enter a verification code. The "funny" is that when I do the same process on an emulator, none of this happens. What might be happening and what is needed to correct the problem?

Below is a print with the exception on the screen.

Here is the code of the confirm page.

//---XAML---\

<?xml version="1.0" encoding="utf-8" ?>``

    <!--#region Imagem de Background-->

    <Image x:Name="imgBackground" Aspect="AspectFill"
            Source="https://sites.google.com/site/clickemenow/arquivos/Background.png?attredirects=0"
            AbsoluteLayout.LayoutBounds="1,1,1,1" AbsoluteLayout.LayoutFlags="All"
            />

    <!--#endregion-->

    <!--#region Imagem Agencia-->

    <Image x:Name="imgAgencia"
        Source="logoflipdigital.png"
        WidthRequest="150"
        HeightRequest="150"
        BackgroundColor="Transparent"
        AbsoluteLayout.LayoutBounds=".5,0,.4,.3" AbsoluteLayout.LayoutFlags="All"
    />

    <Label BackgroundColor="Transparent"
                Text="Flip Digital" FontSize="22" TextColor="White"
                x:Name="lbTitulo"
                Opacity="0.9"
                HeightRequest="60"
                WidthRequest="50"
                VerticalTextAlignment="Center"
                HorizontalTextAlignment="Center"
                AbsoluteLayout.LayoutBounds=".5,.3,.8,.1" AbsoluteLayout.LayoutFlags="All"
           />

    <Label BackgroundColor="Transparent"
                Text="Sua Agência OnLine" FontSize="16" TextColor="White"
                x:Name="lbSubtitulo"
                Opacity="0.9"
                HeightRequest="60"
                WidthRequest="50"
                VerticalTextAlignment="Center"
                HorizontalTextAlignment="Center"
                AbsoluteLayout.LayoutBounds=".5,.35,.8,.1" AbsoluteLayout.LayoutFlags="All"
           />

    <Entry BackgroundColor="White"
                FontSize="18"
                x:Name="txtCodVerificacao"
                Placeholder="Codigo Veficador"
                Opacity="0.6"
                HorizontalTextAlignment="Center"
                HeightRequest="60"
                WidthRequest="50"
                AbsoluteLayout.LayoutBounds=".5,.5,.88,.1" AbsoluteLayout.LayoutFlags="All"
           />

    <!--#endregion-->

    <!--#region Bloco Cadastrar e Nova Senha-->

    <Button BackgroundColor="Teal"
                x:Name="btnReenviar"
                Text="Reenviar código" FontSize="15"
                TextColor="White" Opacity="0.8"
                HeightRequest="60"
                WidthRequest="50"
                AbsoluteLayout.LayoutBounds=".1,.65,.4,.1" AbsoluteLayout.LayoutFlags="All"
           />

    <Button BackgroundColor="Teal"
                x:Name="btnConfirmar"
                Text="Verificar código" FontSize="15"
                TextColor="White" Opacity="0.8"
                HeightRequest="60"
                WidthRequest="50"
                AbsoluteLayout.LayoutBounds=".9,.65,.4,.1" AbsoluteLayout.LayoutFlags="All"
           />
    <!--#endregion-->

</AbsoluteLayout>

//--------------------------C#-----------------------------------\

namespace FlipDigital.Views
{

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class FlipDigital_ConfirmarCadastro : ContentPage
{

    public bool Agencia { get; set; }

    public FlipDigital_ConfirmarCadastro(bool agencia)
    {
        try
        {
            InitializeComponent();
            this.Agencia = agencia;
            btnConfirmar.Clicked += Seguir;
            //BindingContext = new ContentPageViewModel();
        }
        catch (Exception ex)
        {
            DisplayAlert("Exception", ex.Message, "OK");
        }
    }

    private async void ReenviarCodigo(object sender, EventArgs e)
    {
        try
        {

        }
        catch (Exception ex)
        {
            await DisplayAlert("Exception", ex.Message, "OK");
        }
    }

    private async void Seguir(object sender, EventArgs e)
    {
        try
        {
            await DisplayAlert("Alert", "Cadastro confirmado com sucesso. Você está sendo direcionado a pagina inicial do app.", "OK");

            if (Agencia)
            {
                await Navigation.PushAsync(new FlipDigital_InicialAgencia());
            }
            else
            {
                await Navigation.PushAsync(new FlipDigital_InicialCliente());
            }
        }
        catch (Exception ex)
        {
            await DisplayAlert("Exception", ex.Message, "OK");
        }
    }
}

class FlipDigital_ConfirmarCadastroViewModel : INotifyPropertyChanged
{

    public FlipDigital_ConfirmarCadastroViewModel()
    {
        IncreaseCountCommand = new Command(IncreaseCount);
    }

    int count;

    string countDisplay = "You clicked 0 times.";
    public string CountDisplay
    {
        get { return countDisplay; }
        set { countDisplay = value; OnPropertyChanged(); }
    }

    public ICommand IncreaseCountCommand { get; }

    void IncreaseCount() =>
        CountDisplay = $"You clicked {++count} times";


    public event PropertyChangedEventHandler PropertyChanged;
    void OnPropertyChanged([CallerMemberName]string propertyName = "") =>
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

}

}

It is worth mentioning that the exception occurs only in this page, since the navigation of the others happens normally.

Answers

  • sdonaldsonsdonaldson CAMember ✭✭

    Did you find any way around this one? I am experiencing the same error using Xamarin to develop on iOS. Visual Studio 2017 crashes when I attempt to 'Copy Details'

  • LeonardoSilva.6793LeonardoSilva.6793 USMember ✭✭

    I have not been able to resolve this issue yet. This week I will rewrite this page and we will see what it will give. Unfortunately it seems that there are not many answers or concerns regarding this subject and I am in doubt whether the fact is a personal error or an IDE bug.

  • JimmyGarridoJimmyGarrido USXamarin Team Xamurai

    When the debugger breaks on the exception (as shown in the screenshot), what happens when you press "Continue"? Sometimes in these cases, a stacktrace will be printed out in the debug output which could help show what is causing this issue. Can you attach the full debug output as a file in your reply?

    Can you also attach the adb logcat log from the device? This should also hopefully contain some stacktrace information. Thanks!

  • LeonardoSilva.6793LeonardoSilva.6793 USMember ✭✭

    These are some outputs from the debugging process on the device, but I have not yet done the debugging process completely since the app is deployed and soon closes. At another time he does not even start, signaling that he was not able to connect to logcat.

    O aplicativo Android está sendo depurado.
    05-04 00:31:24.921 D/dalvikvm(17008): Late-enabling CheckJNI
    05-04 00:31:25.041 E/dalvikvm(17008): Dex cache directory isn't writable: /data/dalvik-cache
    05-04 00:31:25.041 I/dalvikvm(17008): Unable to open or create cache for /data/app/FlipDigital.Android-1.apk (/data/dalvik-cache/data@app@FlipDigital.Android-1.apk@classes.dex)
    05-04 00:31:25.051 E/GyroEmu (17008): Exception in SystemSensorEvent hook: java.lang.ClassNotFoundException: android.hardware.SystemSensorManager$SensorEventQueue
    05-04 00:31:25.051 D/ActivityThread(17008): setTargetHeapUtilization:0.25
    05-04 00:31:25.051 D/ActivityThread(17008): setTargetHeapIdealFree:8388608
    05-04 00:31:25.051 D/ActivityThread(17008): setTargetHeapConcurrentStart:2097152
    05-04 00:31:25.061 W/ApplicationContext(17008): Unable to create cache directory
    05-04 00:31:25.061 D/AndroidRuntime(17008): Shutting down VM
    05-04 00:31:25.061 W/dalvikvm(17008): threadid=1: thread exiting with uncaught exception (group=0x40f79438)
    05-04 00:31:25.061 E/AndroidRuntime(17008): FATAL EXCEPTION: main
    05-04 00:31:25.061 E/AndroidRuntime(17008): java.lang.NullPointerException
    05-04 00:31:25.061 E/AndroidRuntime(17008): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4118)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at android.app.ActivityThread.handleBindApplication(Native Method)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at android.app.ActivityThread.access$1400(ActivityThread.java:143)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1301)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at android.os.Handler.dispatchMessage(Handler.java:99)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at android.os.Looper.loop(Looper.java:137)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at android.app.ActivityThread.main(ActivityThread.java:4960)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at java.lang.reflect.Method.invokeNative(Native Method)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at java.lang.reflect.Method.invoke(Method.java:511)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
    05-04 00:31:25.061 E/AndroidRuntime(17008): at dalvik.system.NativeStart.main(Native Method)

  • "An unhandled exception occured."

    In my case, the same exception occur, but after debugging, I viewed that error occur when executing an async operation in SQLite. This is the code in my project that triggers the error:

        /// <summary>
        /// Insere os resultados de "Itens a verificar"
        /// </summary>
        /// <param name="resultadoInspecaoItems"></param>
        /// <returns></returns>
        public static async Task<int> Inserir(List<ResultadoInspecaoItem> resultadoInspecaoItems)
        {
            var retorno = await ConexaoSqLite.ConnectionAsync.InsertAllAsync(resultadoInspecaoItems);
            return retorno;
        }
    
Sign In or Register to comment.