1
下面的代码将引发InvalidOperationException,消息:全球集装箱已初始化为什么枚举MEF部件会导致容器初始化失败?
var aggcat = new AggregateCatalog();
aggcat.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly().Location));
// This line does something to the catalog
aggcat.Parts.ToArray();
_container = new CompositionContainer(aggcat, true);
// Exception gets thrown here
System.ComponentModel.Composition.Hosting.CompositionHost.Initialize(_container);
当我注释掉Parts.ToArray()行,它工作正常。这里发生了什么?