Bug 34671 - Mono.Runtime linked away
Summary: Mono.Runtime linked away
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 9.4 (iOS 9.2)
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-10-07 18:16 UTC by Kristian Loekkegaard
Modified: 2015-10-08 20:01 UTC (History)
2 users (show)

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


Attachments
Example solution to reproduce the issue (13.59 KB, application/x-zip-compressed)
2015-10-07 18:16 UTC, Kristian Loekkegaard
Details


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:
Status:
RESOLVED FIXED

Description Kristian Loekkegaard 2015-10-07 18:16:10 UTC
Created attachment 13232 [details]
Example solution to reproduce the issue

When building a Xamarin.iOS project with linking enabled, the type Mono.Runtime is appartently linked away. That means the following returns null: Type.GetType("Mono.Runtime");

This is a problem because this is a common way of evaluating if running on the mono platform. Specifically, I am unable to use Elasticsearch.net with Xamarin, because they use the above call to evaluate whether to set HttpWebRequest.DefaultMaximumErrorResponseLength, which throws a NotImplementedException on Xamarin.

When changing linker behavior to "Don't link" the Mono.Runtime is included and will be returned from the GetType call, and therefore the Elasticsearch.net package works fine.

I attached a clean project where I make the call to Type.GetType("Mono.Runtime"). You should see that when running it with linking enabled, you will get null back, whereas when disabling linking, the type is returned as expected.
Comment 1 Sebastien Pouliot 2015-10-07 21:36:55 UTC
You're right, we should preserve this type. While it's not an issue for applications but it's one for 3rd parties assemblies on which you have, at best, limited control.

You can workaround this today (and still link your application) by:

1. using an XML file to describe what to preserve, e.g.

<linker>
	<assembly fullname="mscorlib">
		<type fullname="Mono.Runtime" />
	</assembly>
<linker>

and add `--xml=myfile.xml` to the "Additional mtouch argument". That will only keep this internal type (no size penalty);

or

2. only disabling linking on mscorlib.dll, i.e. `--linkskip=mscorlib`, which will have some size penalty on your final executable size.
Comment 2 Sebastien Pouliot 2015-10-07 22:03:10 UTC
Fixed in maccore/master 1a4b781a4ad3d230f543f270cb176676982fefc1
Comment 3 Kristian Loekkegaard 2015-10-08 20:01:36 UTC
Thank you for the quick response, Sebastian. And I appreciate the workaround in the meantime as well.