Reputation: 35812
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:
Upvotes: 8
Views: 9418
Reputation: 4807
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!
Upvotes: 11
Reputation: 520
Ill just throw this in the mix. I was getting a "No compatible code running" error when attempting to break on otherwise 'working' code.
After struggling with this I decided to go back to an older version of visual studio where it didn't happening. This gave me the idea to reset my Exception settings, and then the issue went away.
Seemingly there are a number of handled exceptions that any given library might be throwing, and if you choose to break on a particular condition you may well see this.
Upvotes: 0
Reputation: 376
I got similar issue, after investigating, I just have to disable the Xamarin Inspector.
Upvotes: 1
Reputation: 309
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.
Upvotes: 6
Reputation: 496
You can subscribe on each platform main constructor to UnhandledException event this will give you more information about exception before break debug.
for example in Android:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
//subscribe to unhandled event
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
}
If you need each platform explanation ask for them :)
Upvotes: 6