Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
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.
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.
<type fullname="Mono.Runtime" />
and add `--xml=myfile.xml` to the "Additional mtouch argument". That will only keep this internal type (no size penalty);
2. only disabling linking on mscorlib.dll, i.e. `--linkskip=mscorlib`, which will have some size penalty on your final executable size.
Fixed in maccore/master 1a4b781a4ad3d230f543f270cb176676982fefc1
Thank you for the quick response, Sebastian. And I appreciate the workaround in the meantime as well.