Context
I am using VS 2017.3 to develop Xamarin.Forms application. I am trying to diagnose where and why an Exception occur on my code.
I can successfully deploy run and debug my application using the SDK Android Emulator (HAX x86).
However in case an Exception occur I can not see any information about the Exception, see attached picture, settings.
Question
Is this normal in Android debugging, or missing I something?
...and my build settings:
Enable native code debugging in the properties. For C#, select Debug in the left pane, select Open debug launch profiles UI, then select the Enable native code debugging check box, and then close the properties page to save the changes.
I wanted to expand on @Uraitz's answer because it helped me figure out the problem.
First, as he explains, you will want to add an event handler in your activity, as shown in the following code:
protected override void OnCreate(Bundle savedInstanceState)
{
...
//subscribe to unhandled event
AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
...
}
private void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
In my case I put a breakpoint inside CurrentDomainUnhandledException
so I could inspect the exception.
However, even with that breakpoint in there, I ran my code and still got a confusing no-callstack error.
At this point I thought the solution wasn't working. In fact it is, but I had to click the Play (continue) button multiple times before my app would hit the breakpoint:
After clicking that button two times, I finally hit the breakpoint:
If you want to get the callstack in the debugger, you will have to dive in a few levels before it is available, but you can do so by looking at the event args parameter.
The moral of the story is - if you have added the event handler but you still aren't hitting the breakpoint (or seeing output) - keep clicking the Continue button!
Just continue, then look through the Output, it will show you the stack trace of the exception. It is a good idea to learn how to read through the log files to find information about exceptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With