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.
Using the GetProperty() method of Type, a PropertyInfo for the HighlightedImage property of the UIImageView class can be retrieved when running on an iOS 7.0.3 simulator on OS X, but when running the same code on an iPad running iOS 7.0.3, null is returned.
HighlightedImage is a public instance property of UIImageView so there should not be any problems with retrieving information about it through reflection.
The following line of code, run on the simulator and a device, should make the issue apparent:
System.Reflection.PropertyInfo pi = typeof(MonoTouch.UIKit.UIImageView).GetProperty("HighlightedImage");
pi will be null when run on a device, but will have the expected value when run on a simulator.
That's normal. The (managed) linker  is enabled, by default, on device builds and will remove unused code - while it's not enabled on simulator builds.
The linker use static analysis to detect what's must be kept inside the application. Static analysis cannot detect reflection usage (it's dynamic) so you'll need to give some hints to the linker.
One way to hint this is to add a bit of extra code. If your application uses the property (make sure to use both getter and setters if you need both) then it will be kept and available for reflection at runtime.
E.g. a static ctor (which the linker won't remove) could do something like:
static MyType ()
UIImageView v = null;
if (v != null) v.HighlightedImage = v. HighlightedImage;
that will hint the linker to keep both getter and setter (without really executing the code).
Ah, I had forgotten about that particular functionality in the linker...thanks Sebastien!