Bug 41849 - Issues with AggregateCatelog (CompositionContainer) in MEF
Summary: Issues with AggregateCatelog (CompositionContainer) in MEF
Status: RESOLVED ANSWERED
Alias: None
Product: Installers
Classification: Mono
Component: General ()
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Alexander Köplinger [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2016-06-15 13:02 UTC by Howard Glenn Inman
Modified: 2016-07-04 20:01 UTC (History)
1 user (show)

Tags:
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 GitHub or Developer Community 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 ANSWERED

Description Howard Glenn Inman 2016-06-15 13:02:33 UTC
The code below (even if a valid (Not Null) AggregateCatalog is provided) gives the error.

System.MissingMethodException: Method 'Array.Empty' not found.

                 
                using (CompositionContainer container = new CompositionContainer((AggregateCatalog)null))
                {
                }
Comment 1 Howard Glenn Inman 2016-06-17 18:44:36 UTC
An update that might help you debug.

This code will throw the "System.MissingMethodException: Method 'Array.Empty' not found." error.

        #region Container
        /// <summary>
        /// Gets the container.
        /// </summary>
        /// <value>The container.</value>
        private CompositionContainer ContainerOrig
        {
            get
            {
                if(null == _Container)
                {
                    _Container = new CompositionContainer(Catalog);
                }

                return _Container;
            }
        }

However after using IlSpy to see what is going on in System.ComponentModel.Composition.Hosting I created this Change (so I don't pass an empty array. Hope this helps

        private CompositionContainer Container
        {
            get
            {
                if (null == _Container)
                {
                    ComposablePartExportProvider partExport = new ComposablePartExportProvider(CompositionOptions.Default);
                    CatalogExportProvider catalogExport = new CatalogExportProvider(Catalog, CompositionOptions.Default);

                    ExportProvider[] providers = new ExportProvider[1];
                    providers[0] = new AggregateExportProvider(new ExportProvider[]
                    {
                        partExport,
                        catalogExport
                    });


                    _Container = new CompositionContainer(Catalog, CompositionOptions.Default, providers);
                    partExport.SourceProvider = _Container;
                    catalogExport.SourceProvider = _Container;
                }

                return _Container;
            }
        }
Comment 2 Howard Glenn Inman 2016-06-17 20:06:10 UTC
I think I spoke to soon.
I will keep looking into a work around
Comment 3 Howard Glenn Inman 2016-06-19 19:26:10 UTC
I have verified that that does resolve the issue for this problem, perhaps it can lead you to a better resolution

Thanks
Comment 4 Rodrigo Kumpera 2016-07-04 19:57:14 UTC
I think Array.Empty was later added to 4.4. Howard, can you try with that version?

Alexander, can you help us with this one?
Comment 5 Alexander Köplinger [MSFT] 2016-07-04 20:01:20 UTC
That is correct, Array.Empty<T> was added in Mono 4.4.

I tried the code you posted in #c0 and it doesn't throw the exception for me. I'm closing this, please reopen if you run into issues with Mono 4.4. Thanks!