Bug 55087

Summary: System.NotSupportedException: Stack walks are not supported on this platform - System.Reflection.MethodBase.GetCurrentMethod
Product: Android Reporter: Chris Riesgo <cmriesgo>
Component: Mono runtime / AOT CompilerAssignee: Zoltan Varga <vargaz>
Status: VERIFIED FIXED    
Severity: blocker CC: AnatoliiB, brandon.minnick, brendan.zagaeski, cmriesgo, Daniel.Regner, dan.rigby, gcrockenberg, grendel, jomarj, jon.goldberger, lgmaestrelli, ludovic, luis.aguilera, miguel, mono-bugs+monodroid, mono-bugs+mono, olaa81, vargaz, v-prala, v-sapaun
Priority: Highest    
Version: unspecified   
Target Milestone: 15.2.2   
Hardware: Macintosh   
OS: Mac OS   
Tags: 15.2KI Is this bug a regression?: Yes
Last known good build: XA 7.2.x
Attachments: Visual Studio install details
Xamarin.Android Repro App
Preview 10 VS for Mac Details
API23 x86_64 Google Emulator
Android 7.3.0.13 Crash Log
Logs Generated when issue is reproduced
IDE Logs

Description Chris Riesgo 2017-04-12 13:29:12 UTC
Created attachment 21468 [details]
Visual Studio install details

In the current preview of Mono 5, there seems to be a bug, regression, or missing functionality around "System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;". 

I consistently receive this exception:

System.NotSupportedException: Stack walks are not supported on this platform.
  at (wrapper managed-to-native) System.Reflection.MethodBase:GetCurrentMethod ()

I'm attaching a sample Xamarin.Android app that demonstrates the issue. This same code works fine in the latest stable version of Mono.
Comment 1 Chris Riesgo 2017-04-12 13:29:51 UTC
Created attachment 21469 [details]
Xamarin.Android Repro App
Comment 2 Zoltan Varga 2017-04-24 20:32:12 UTC
Does this  happen on a simulator, or on a real device ?
Comment 3 Chris Riesgo 2017-04-24 20:52:44 UTC
For sure on a Google API 23 emulator
Comment 4 Chris Riesgo 2017-04-25 13:36:13 UTC
@Zoltan - Some additional info I gathered this morning

Also crashes on:
Google API 24 emulator
Google API 25 emulator

NO crash on:
Moto E 2nd gen API 22 (debug & release build configurations)
Nexus 5 hardware API 23 (debug & release build configurations)
Nexus 6P hardware API 25  (debug & release build configurations)
Comment 5 Chris Riesgo 2017-05-03 12:59:23 UTC
@Zoltan - I might have some additionally useful information. 

Running on x86_64 emulator image
---------------------------------
x86 ABI selected + x86_64 ABI unselected       => WORKS!!
x86 ABI unselected + x86_64 ABI selected       => crash
Comment 6 Chris Riesgo 2017-05-08 23:35:21 UTC
Created attachment 22012 [details]
Preview 10 VS for Mac Details
Comment 7 Chris Riesgo 2017-05-08 23:36:36 UTC
Created attachment 22013 [details]
API23 x86_64 Google Emulator

Here's one example of an Android emulator where the repro app crashes. Please note that you need to click the button to observe the crash.
Comment 8 Chris Riesgo 2017-05-08 23:57:03 UTC
Here's the crash stack:

CrashTest Exception: System.NotSupportedException: Stack walks are not supported on this platform.
  at (wrapper managed-to-native) System.Reflection.MethodBase:GetCurrentMethod ()
  at CrashTest.MainActivity.GetDeclaringType () [0x00002] in /Users/chrisr/Downloads/CrashTest/CrashTest/MainActivity.cs:37
Comment 9 Jon Goldberger [MSFT] 2017-05-09 01:30:54 UTC
Setting as confirmed as I can reproduce this issue when running the test project on a Google x86_64 emulator running Marshmallow. 

## Steps to reproduce:

1. Load the Repro app
2. Open the Android Project Options->Android Build->Advanced tab
3. Deselect all supported ABIs EXCEPT x86_64
4. Build and run the app to an x86_64 emulator
5. Click the button

Expected result: Button's text will be updated to say "1 MainActivity Clicks!"

Actual result: App crashes with exception and stack trace below:

>System.NotSupportedException: Stack walks are not supported on this platform.
>  at at (wrapper managed-to-native) System.Reflection.MethodBase:GetCurrentMethod ()
>  at CrashTest.MainActivity.GetDeclaringType () [0x00022] in /Users/jongoldberger/Downloads/CrashTest/CrashTest/MainActivity.cs:42
>  at CrashTest.MainActivity+<>c__DisplayClass1_0.<OnCreate>b__0 (System.Object <p0>, System.EventArgs <p1>) [0x00001] in /Users/jongoldberger/Downloads/CrashTest/CrashTest/MainActivity.cs:28
>  at Android.Views.View+IOnClickListenerImplementor.OnClick (Android.Views.View v) [0x00011] in <33e6e739ac344166b157e323586f11a1>:0
>  at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x0000f] in <33e6e739ac344166b157e323586f11a1>:0
>  at at (wrapper dynamic-method) System.Object:d5595756-92bd-4e78-9420-4ec888bd7ea4 (intptr,intptr,intptr)

## Environment

=== Visual Studio for Mac Preview ===

Version Preview 10 (7.0 build 3051)
Installation UUID: f86726f2-bd5d-4610-867e-44e82f306ca2
Runtime:
	Mono 5.0.0.94 (2017-02/1d0445b) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 500000094

=== NuGet ===

Version: 4.0.0.2323

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
SDK: /usr/local/share/dotnet/sdk/1.0.1/Sdks
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.0.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.5.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.3.2 (12175)
Build 8E2002

=== Xamarin.Android ===

Version: 7.3.0.13 (Visual Studio Enterprise)
Android SDK: /Users/jongoldberger/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		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)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)
		7.0   (API level 24)
		7.1   (API level 25)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.5
SDK Build Tools Version: 25.0.2

Java SDK: /usr
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Inspector ===

Version: 1.2.2
Hash: b71b035
Branch: d15-1
Build date: Fri, 21 Apr 2017 17:57:12 GMT

=== Xamarin.Mac ===

Version: 3.4.0.30 (Visual Studio Enterprise)

=== Xamarin.iOS ===

Version: 10.10.0.30 (Visual Studio Enterprise)
Hash: 30b6e87e
Branch: d15-2
Build date: 2017-04-28 17:17:13-0400

=== Build Information ===

Release ID: 700003051
Git revision: e5296061de5c6b093fb59668526728f2b82caa91
Build date: 2017-05-01 09:58:05-04
Xamarin addins: 7123ae956f3089f398cc9eae6bba94037ca896e6
Build lane: monodevelop-lion-d15-2

=== Operating System ===

Mac OS X 10.12.4
Darwin 16.5.0 Darwin Kernel Version 16.5.0
    Fri Mar  3 16:52:33 PST 2017
    root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
Comment 10 Chris Riesgo 2017-05-09 01:32:10 UTC
Created attachment 22014 [details]
Android 7.3.0.13 Crash Log

Seems the issue is specific to Android version 7.3.x. 

If I upgrade ONLY Visual Studio for Mac to Preview 10 (leaving all other SDKs on Stable), my sample app works. If I then update Android from 7.2.x to 7.3.x, then the app begins to crash.
Comment 11 Zoltan Varga 2017-05-10 01:18:25 UTC
https://github.com/mono/mono/pull/4819
Comment 12 Zoltan Varga 2017-05-10 15:01:02 UTC
Should be fixed on mono 2017-02 branch by 1298269b88479747947d332c8ae7c0e8222a3b8c.

Could somebody bump xam.android to that revision or cherry-pick-it into a branch ?
Comment 13 Ashley Gazich [MSFT] 2017-05-11 17:37:32 UTC
*** Bug 56233 has been marked as a duplicate of this bug. ***
Comment 14 Brendan Zagaeski (Xamarin Support) 2017-05-11 22:02:44 UTC
## Additional tallying

4 other users: https://forums.xamarin.com/discussion/92934/ (2017-04-11 to 2017-05-11)
3 other users: https://forums.xamarin.com/discussion/92937/ (2017-04-11 to 2017-05-10)
1 other user:  https://forums.xamarin.com/discussion/93430/ (2017-04-18 to 2017-04-27)

0 other users: https://forums.xamarin.com/discussion/93975/ (2017-04-24, from the reporter of this bug)
Comment 15 Saurabh Paunikar 2017-05-15 13:28:41 UTC
Reopening this issue as in mono version I found that application crashes

In comment 9 it is mentioned that 
Expected result : Button's text will be updated to say "1 MainActivity Clicks!"  when button is clicked  

But it was found that application crashes when button is clicked

ScreenCast link:https://www.screencast.com/t/LC0HaXJABl
Comment 16 Saurabh Paunikar 2017-05-15 13:29:48 UTC
Created attachment 22168 [details]
Logs Generated when issue is reproduced
Comment 17 Ludovic Henry 2017-05-15 15:07:11 UTC
@Saurabh you didn't test the fix as the android version you have is too old. First a bump on Android need to happen before you test it.
Comment 18 Pratik Lad 2017-05-16 09:15:37 UTC
Hello,
Verified the bug on build :-
Visual Studio Enterprise 2017 for Mac Version 7.0.1 (build 2)
Xamarin.Android Version: 7.3.0.15
Xamarin.iOS Version: 10.10.0.33
Xamarin.Mac Version: 3.4.0.33

Screen cast link :-
http://www.screencast.com/t/jRMO5lF6DGDW

Build Information :-
https://gist.github.com/p-lad/dbda4c5bccb10368be31fcc08a526c49

As I have verified this bug can you please mark the bug resolved so that i can mark it as verified.

Thanks.
Comment 19 Pratik Lad 2017-05-16 09:29:37 UTC
Created attachment 22189 [details]
IDE Logs
Comment 20 Mobigital 2017-05-17 19:00:08 UTC
I am experiencing the same issue, is there a workaround or expected fix date?
Comment 21 Brendan Zagaeski (Xamarin Support) 2017-05-17 19:07:19 UTC
@Mobigtal, a workaround is to use an x86 Android emulator rather than an x86_64 Android emulator or to deselect the x86_64 Android ABI, as mentioned in Comment 5.  The candidate fix as verified on Comment 18 and Comment 19 is targeted to the Xamarin 15.2.2 release as indicated by the Target Milestone field of the bug.  The Xamarin 15.2.2 release is tentatively scheduled for release by the end of this week.
Comment 22 Rodrigo Kumpera 2017-05-26 20:01:16 UTC
*** Bug 55602 has been marked as a duplicate of this bug. ***