Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Android debugging: No compatible code running

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?

enter image description here

...and my build settings:

enter image description here

like image 981
g.pickardou Avatar asked Sep 21 '17 12:09

g.pickardou


People also ask

How do I enable native code debugging?

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.


2 Answers

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.

enter image description here

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:

enter image description here

After clicking that button two times, I finally hit the breakpoint:

enter image description here

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.

enter image description here

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!

like image 188
Victor Chelaru Avatar answered Nov 15 '22 06:11

Victor Chelaru


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.

like image 38
Joagwa Avatar answered Nov 15 '22 08:11

Joagwa