Bug 26430 - Linker stripping out types that are referenced in attributes
Summary: Linker stripping out types that are referenced in attributes
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 8.6.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: 8.10
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2015-01-26 15:51 UTC by Randall Schmidt
Modified: 2015-02-06 11:50 UTC (History)
2 users (show)

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


Attachments
Reproduction case (11.66 KB, application/zip)
2015-01-26 15:51 UTC, Randall Schmidt
Details


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 FIXED

Description Randall Schmidt 2015-01-26 15:51:37 UTC
Created attachment 9507 [details]
Reproduction case

The linker seems to be stripping out types that are referenced in attributes, if they are passed into the attribute's constructor in an array.

Attached is a reproduction case.
Expected behavior: does not throw exception
Exhibited behavior: throws System.TypeLoadException

The project has two separate implementations of the CustomAttribute class. One is commented out. That one does not cause the app to crash.
Comment 1 Sebastien Pouliot 2015-01-26 21:31:10 UTC
_Supporting_ `System.Type` in attributes was a recent (not original) addition to the linker. It's a common pattern but it does not always mean what you want, e.g. it will preserve the type itself (not all it's members).

I'll look at adding support for arrays (but they will face the same limitation, i.e. their usage is generally done thru reflection and the linker can't see that using static analysis).

In the meantime the workaround is to include something like:

>			var t = typeof(CustomType);

somewhere in your code (e.g. in FinishedLaunching). That will ensure the type is not removed.
Comment 2 Sebastien Pouliot 2015-02-05 15:24:28 UTC
Fixed in mono/master 7b29d5abb27b20d336c62f6404efb8cf65df6847

This should be picked up for XI 8.10, keeping open until bump happen.
Comment 3 Sebastien Pouliot 2015-02-06 11:50:14 UTC
Bumped in master / 4c3e89f3b336e397384694b5343246d7415fae88

QA: unit tests added in the same revision