Bug 10580 - Detect Mono using Mono.Runtime class fails in Release
Summary: Detect Mono using Mono.Runtime class fails in Release
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.4.x
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Alex Rønne Petersen
Depends on:
Reported: 2013-02-22 08:31 UTC by Alan McFarlane
Modified: 2013-07-11 11:43 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Alan McFarlane 2013-02-22 08:31:30 UTC
From http://forums.xamarin.com/discussion/1551/detect-mono-using-mono-runtime-class

February 21 in Android
To detect if running on Mono, my code has used the recommendation from http://www.mono-project.com/FAQ:_Technical of Type.GetType("Mono.Runtime");  This seems to not work on an Android Release build. Does that sound right?

Jonathan Pryor
February 21
> This seems to not work on an Android Release build. Does that sound right?

It's plausible (probable) that we're linking it away. We should probably fix the linker to not remove Mono.Runtime; could you please file a bug for this?

A workaround would be to check for an internal type which isn't likely to disappear. Mono.Runtime would be ideal, but as that's probably being linked away, you should try loading System.MonoType. That's not documented as being stable, but the linker won't remove that type (unless you use no Reflection at all...?), and I don't foresee it being renamed anytime soon.

Type monoSpecificType = Type.GetType ("Mono.Runtime") ?? Type.GetType ("System.MonoType");
bool runningOnMono = monoSpecificType != null;
Comment 1 Alex Rønne Petersen 2013-06-01 00:09:59 UTC
We now always preserve the Mono.Runtime type.
Comment 2 Nischal 2013-06-12 04:21:55 UTC
Today we have checked this issue with following builds:

All Windows and Mac
X.S 4.0.9(build 3)
Xamarin.Android 4.7.9-1

And we followed following code in console project which is mentioned in gist: https://gist.github.com/atin360/d2337e1d79af774d8eab and run the project and getting wrong output this is the screencast for the same: http://screencast.com/t/cL1DwNjdhJD

While on Mac we are getting correct output like "Hello World! you are running with the mono VM"

Hence, Reopening this issue.
Comment 3 Alex Rønne Petersen 2013-06-12 08:24:33 UTC
Nischal, this is a bug that occurred on device only. The reason you do not get the expected result on Windows is that, for desktop apps, XS defaults to the .NET runtime. To verify that this is fixed, you must check it with an app that runs on an Android device.
Comment 4 Peter Collins 2013-06-13 18:36:54 UTC
Using the gist from Comment 2, I can confirm we are preserving the Mono.Runtime type when deploying to a physical Android device from OSX.

Nischal, please add your test code to an android project, and deploy to device from Windows to verify this as fixed.