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 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.
Created attachment 9507 [details]
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.
_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.
Fixed in mono/master 7b29d5abb27b20d336c62f6404efb8cf65df6847
This should be picked up for XI 8.10, keeping open until bump happen.
Bumped in master / 4c3e89f3b336e397384694b5343246d7415fae88
QA: unit tests added in the same revision