Bug 29063 - Linker strips methods from MEF ExportfactoryCreator
Summary: Linker strips methods from MEF ExportfactoryCreator
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 8.8.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: 8.13 (C6 alpha)
Assignee: Sebastien Pouliot
Depends on:
Reported: 2015-04-13 18:08 UTC by jesse.attas
Modified: 2015-04-15 08:34 UTC (History)
2 users (show)

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

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 jesse.attas 2015-04-13 18:08:32 UTC
I'm getting a NullReferenceException in CreateStronglyTypedExportFactoryFactory in /Library/Frameworks/Xamarin.iOS.framework/Versions/

The exception happens when it tries to call 
                genericMethod = _createStronglyTypedExportFactoryOfTM.MakeGenericMethod(exportType, metadataViewType);

The member variable is null. This only happens if Link SDK or Link All Assemblies. If Link None, this code works fine. This makes sense because the member variable is initialized by reflection:
        private static readonly MethodInfo _createStronglyTypedExportFactoryOfTM = typeof(ExportFactoryCreator).GetMethod("CreateStronglyTypedExportFactoryOfTM", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

As a workaround, I am able to set --linkskip=System.ComponentModel.Composition.
Comment 1 Sebastien Pouliot 2015-04-15 08:34:25 UTC
The workaround is fine - and might still be needed for other cases beyond the one we can deal with, e.g.

* ExportFactoryCreator.CreateStronglyTypedExportFactoryOfT [1]
* ExportFactoryCreator.CreateStronglyTypedExportFactoryOfTM [1]
* ExportServices.CreateStronglyTypedLazyOfT [2]
* ExportServices.CreateStronglyTypedLazyOfTM [2]
* ExportServices.CreateSemiStronglyTypedLazy [2]

^ Those will (or are) be handled automatically by the linker in future [1] (or existing [2]) versions of XI.

OTOH MEF is quite dynamic in nature so overall YMMV, i.e. there are other cases that cannot be predicted.

Fixed in maccore/master a6d6a7077cbfc1f484e8bafd604c7a8db56a7d47

QA: unit tests added in the same revision