title: Exception In Xamarin Forms and Visual Studio - An unhandled exception occured
body: <p>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?</p>
  
  <p>Below is a print with the exception on the screen.
  <a href="https://i.stack.imgur.com/eietW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eietW.png" alt="enter image description here"></a>
  Here is the code of the confirm page.</p>
  
  <p><strong>//---XAML---\</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8" ?&gt;``
  &lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
               xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
               x:Class="FlipDigital.Views.FlipDigital_ConfirmarCadastro"
               Title="Confirmar Cadastro"&gt;
      &lt;AbsoluteLayout&gt;
  
          &lt;!--#region Imagem de Background--&gt;
  
          &lt;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"
                  /&gt;
  
          &lt;!--#endregion--&gt;
  
          &lt;!--#region Imagem Agencia--&gt;
  
          &lt;Image x:Name="imgAgencia"
              Source="logoflipdigital.png"
              WidthRequest="150"
              HeightRequest="150"
              BackgroundColor="Transparent"
              AbsoluteLayout.LayoutBounds=".5,0,.4,.3" AbsoluteLayout.LayoutFlags="All"
          /&gt;
  
          &lt;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"
                 /&gt;
  
          &lt;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"
                 /&gt;
  
          &lt;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"
                 /&gt;
  
          &lt;!--#endregion--&gt;
  
          &lt;!--#region Bloco Cadastrar e Nova Senha--&gt;
  
          &lt;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"
                 /&gt;
  
          &lt;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"
                 /&gt;
          &lt;!--#endregion--&gt;
  
      &lt;/AbsoluteLayout&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p><strong>//---C#---\</strong></p>
  
  <pre><code>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() =&gt;
              CountDisplay = $"You clicked {++count} times";
  
  
          public event PropertyChangedEventHandler PropertyChanged;
          void OnPropertyChanged([CallerMemberName]string propertyName = "") =&gt;
              PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  
      }
  }
  </code></pre>
  
  <p>It is worth mentioning that the exception occurs only in this page, since the navigation of the others happens normally.</p>