Bug 28552 - Reflection of Propertyinfo GetGetmethod throws null reference exception. Xamarin iOS
Summary: Reflection of Propertyinfo GetGetmethod throws null reference exception. Xama...
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 8.8.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-03-30 12:01 UTC by Dinesh kumar
Modified: 2015-03-30 15:13 UTC (History)
3 users (show)

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

Exception screen shot (261.67 KB, image/png)
2015-03-30 12:01 UTC, Dinesh kumar
Build Logs (36.20 KB, text/rtf)
2015-03-30 15:00 UTC, Dinesh kumar
Updated Build Logs as per your comment (36.94 KB, text/rtf)
2015-03-30 15:07 UTC, Dinesh kumar

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:

Description Dinesh kumar 2015-03-30 12:01:07 UTC
Created attachment 10558 [details]
Exception screen shot

Am storing the Reflected properties of an underlying collection into my own Dictionary<string, propertyinfo> for some internal use. 

When i try to use the generic methods "GetGetMethod()" with the Propertyinfo stored in the dicitonary am getting Null Reference exception.

When i examined further deeply i saw that 

System.Reflection.Memberinfo had GetMethod = null. 

The logic used to store the reflected properties -> 

1.Converting the Underlying collection to IEnumerable 

2.Getproperties from  Enumerable.GetType() Stored --> Result is stored inside the Dictionary<Property.Name, Property>

I have attached the screenshots of the expection. 

FYI this worked fine before last update i think this is a break and this reproduces both in Simulator and Devices. The same set of code works fine in Android as am sharing reflection logics across platforms. 

System Information : Xamarin.IOS Business version. 

Am sorry i couldn't reproduce the same issue in a simple sample. It would be great if you come up with some fix or workaround as we are near Product release it would be harder to bear the delay.
Comment 1 Sebastien Pouliot 2015-03-30 14:10:16 UTC
It looks like you have the linker enabled (maybe "Link all" ?) and that member (the getter) is being removed because it's not used by the application.

Can you attach your build logs ?

Please add "-v -v -v -v" to the Project's options, Additiona touch arguments) and do a Rebuild to get the logs and then attach them to the bug report.
Comment 2 Dinesh kumar 2015-03-30 15:00:15 UTC
Created attachment 10565 [details]
Build Logs

Yes you're right my build options has linker enabled "Link All " when i added the monotouch arguments as like you recommended it's working as expected.  I have attached the Build logs for your reference please check it out.
Comment 3 Dinesh kumar 2015-03-30 15:07:04 UTC
Created attachment 10566 [details]
Updated Build Logs as per your comment

Am sorry please ignore the last update it was built using Lineker options "Dont Link" please use the Updated Build Logs. Am still getting those  Null Reference Exception from MethodInfo.
Comment 4 Sebastien Pouliot 2015-03-30 15:13:58 UTC
Your build logs are not helpful since you did not do a "Rebuild" (it did not run mtouch for a Build, since it was already done). As such I cannot see which options were used.

OTOH the NRE is perfectly normal if you use "Link all" (1). When you use this option you are responsible to ensure your code (not the SDK code) is linker safe, i.e. that everything can be reached by static analysis.

That can be done with additional code (i.e.making sure the getter are used), using the [Preserve] attribute or an XML file. Anything not used (or preserved) will be removed by the managed linker (it's its job to do so and you're asking it to run on _all_ code).


1. this is why the default option is "Link SDK", i.e. that the linker is only applied to the SDK code that Xamarin ships (and that user code is not linked). That removes almost all needs for extra code/definitions and still gives great space savings;

2. Using "Link all" in Xamarin.Android would give you the same result;