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.
The following code works in the simulator, but fails in the device;
public void SomeApplicationMethod()
UITextView textView = new UITextView();
public void SomeLibraryMethod(object value)
// returns null for UITextView
PropertyInfo propertyInfo = value.GetType().GetProperty("Text");
The code works on the device when --nolink is used.
I also tried to use --linkskip=monotouch but compilation fails.
(Anecdotally --linkskip=mscorlib builds fine but obviously doesn't fix the issue).
That's normal. The linker is doing it's job and removes things that is not used. It works on the simulator because it defaults to "Don't link" while the devices builds defaults to "Link SDK assemblies only" (in each case it's the fastest option).
Things you can do are:
a) turn off linking completely, e.g. --nolink
b) turn off linking partially, e.g. --linkskip=monotouch
note: the type resides in monotouch.dll (not mscorlib.dll)
c) help the linker, use the type without reflection (even if unused) so it won't be eliminate and will be available (elsewhere in your code) for your reflection usage.
 from the static analysis done by the linker, reflection is not covered (e.g. "Text"
As I said, I tried using --linkskip=monotouch but the build process failed with a NullReferenceException.
I resolved this by add a dummy method that accessed the property I needed, and marking it with [Preserved].