After upgrading Xamarin Android from 4.12.1 to 4.20, we are loosing the callstack info for unhandled exceptions. It only happens in Release build (Debug build shows whole callstack). Try following code:
static void aaa()
throw new Exception("Test");
static void bbb()
static void ccc()
Calling ccc(); will crash and prints out the whole callstack (aaa/bbb/ccc) in Debug, but it only prints ccc in Release. It relates to all exceptions re-thrown from catch block.
It does not happen with Xamarin Android 4.12.1.
I have checked this issue and able to reproduce this. To reproduce this issue I have followed the steps mentioned below:
1. Create an android application in XS.
2. Open MainActivity.cs file and paste the above code in this class.
3. Call ccc(); method at clcick event of button.
4. Build app, set configuration to Release, deploy it on emulator.
5. Application will deploy , click on button.
6. Observed that exception will not show in call stack.
I also observed that when user call ccc(); it crash and prints out the whole call stack in Debug mode.
Application Output: https://gist.github.com/Rajneesh360Logica/21bb265d3a27daf60e61
Build Output: https://gist.github.com/Rajneesh360Logica/2afe653b38d77dcad9c4
XS Logs: http://www.screencast.com/t/PziY4wpg
=== Xamarin Studio ===
Version 5.7 (build 661)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Mono 3.12.0 ((detached/1538a59)
GTK+ 2.24.23 (Raleigh theme)
Package version: 312000072
=== Apple Developer Tools ===
Xcode 6.1 (6604)
=== Xamarin.iOS ===
Version: 126.96.36.199 (Business Edition)
Build date: 2015-01-06 17:56:14-0500
=== Xamarin.Android ===
Version: 188.8.131.52 (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
Supported Android versions:
2.1 (API level 7)
2.2 (API level 8)
2.3 (API level 10)
3.1 (API level 12)
4.0 (API level 14)
4.0.3 (API level 15)
4.1 (API level 16)
4.2 (API level 17)
4.3 (API level 18)
4.4 (API level 19)
4.4.87 (API level 20)
5.0 (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
=== Xamarin.Mac ===
Version: 184.108.40.206 (Business Edition)
=== Build Information ===
Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 16:31:31-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7
=== Operating System ===
Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
Sun Aug 17 19:50:11 PDT 2014
I have further inspected this issue (trying to find the workaround) and it seems that the problem isn't in the re-throwing itself but the callstack is lost before the catch block is executed:
catch (Exception e)
Print(e.ToString()); // the callstack is lost even here
the finally block looses the callstack too (even if it is empty).
There is no way to make it work.
We are observing bug-reports with incomplete callstack. That's really bad. And the downgrade isn't possible due to the missing Lollipop compatibility.
The funny thing is that when I'm running the Release build under debugger, the callstacks are fine.
Please forget my sample, it looses the callstack due to the compiler optimization. I'm sorry.
However, there is really a problem with the throw; statement.
In version 4.12.1, the rethrown exception contained full callstack, while in 4.20, it contains only a part of callstack from the exception point to the first catch block.
It is often in the low-layer library and we don't see who called it. Underlying callstack is lost.
It happens also in Debug and I am afraid (but not sure) that it also relates to iOS, where it behaves this way for a longer time.