Bug 2022 - System.Type.GetProperty(String) returns null for Monotouch.UIKit.UITextView.Text in device.
Summary: System.Type.GetProperty(String) returns null for Monotouch.UIKit.UITextView.T...
Status: RESOLVED FEATURE
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-11-14 06:41 UTC by Jahmai
Modified: 2011-11-14 20:01 UTC (History)
2 users (show)

Tags:
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:
Status:
RESOLVED FEATURE

Description Jahmai 2011-11-14 06:41:16 UTC
The following code works in the simulator, but fails in the device;

public void SomeApplicationMethod()
{
    UITextView textView = new UITextView();

    SomeLibraryMethod(textView);
}

...

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).
Comment 1 Sebastien Pouliot 2011-11-14 09:16:14 UTC
That's normal. The linker is doing it's job and removes things that is not used[1]. 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.

[1] from the static analysis done by the linker, reflection is not covered (e.g. "Text"
Comment 2 Jahmai 2011-11-14 20:01:27 UTC
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].