Bug 2101 - Linker causing PropertyInfo.CanWrite to be always false
Summary: Linker causing PropertyInfo.CanWrite to be always false
Alias: None
Product: iOS
Classification: Xamarin
Component: Debugger ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-11-20 14:54 UTC by Ian
Modified: 2011-11-20 16:39 UTC (History)
2 users (show)

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

example of problem (122.79 KB, image/jpeg)
2011-11-20 14:54 UTC, Ian

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 Ian 2011-11-20 14:54:38 UTC
Created attachment 914 [details]
example of problem

Please see attached screen shot of settings and code.

Basically, when the project is set to link everything in the simulator, the PropertyInfo.CanWrite on a reflected object returns False always.

Code in screenshot from Tweetstation's sqldata class used in my project.
Comment 1 Sebastien Pouliot 2011-11-20 16:39:09 UTC
This is normal because:

a) CanWrite returns true only if the property has a 'setter' method;

b) The static analysis of the linker cannot detect the use of reflection that indirectly use a setter (or a getter or invoking...)

c) The linker will eliminate unused setters from properties (it's part of its job);

Workarounds are (in order of preference):

1) Add a [Preserve] attribute on the setter (or of the type with AllMembers=true) so the linker won't eliminate it;

2) Use the setter somewhere inside your code - so the linker will see it's 'used' by the application;

3) Use "--linkskip=XXX" where XXX is the assembly where the setter is located. The linker won't link that specific assembly (but the rest of your application will be linked);

4) Use "--linksdk" (i.e. "Link SDK assemblies only") so that user code won't be linked (and that will include the setter)