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 for Bug 10739 on
Developer Community or GitHub if you have new
information to add and do not yet see a matching new report.
If the latest results still closely match this report, you can use the
In special cases on GitHub you might also want the comments:
GitHub Markdown with public comments
Linker does not remove unused fields initialisers. There are quite few examples with code which is never used by simple app (e.g hello world) but still not removed by linker in mscorlib.
With the exception of the bindings, which are marked [CompilerGenerated] for safety, the linker does not re-write IL because it can be pretty complex.
What happens is that the fields are not really unused, from the linker perspective, and get marked because:
a) the type, e.g. System.GC, was marked;
b) the static constructor is marked (because the type was marked and the static ctor, if present, needs to be run);
c) the IL scan of the .cctor marks every field being used (the stsfld);
In this case (GC) it's a good thing since the field is initialized to the return value of an internal call - and the linker cannot know if that call has side effects (even if the field is never used elsewhere).
There are other cases where the fields could have been:
* assigned values that would not have side effects (that removes calls, including object creation); and
* are not used outside the .cctor
To deal with them we would need to change how marking is done - not impossible but not easy either. If there's not many of them we could have special rules for the most common/costly .cctors.
This bug was targeted for a past milestone, moving to the next non-hotfix active milestone.