Managed Extensibility Framework
1 TopicMEF's CompositionException issue with MSIX
I am developing a C# project relying on Managed Extensibility Framework (MEF) to do its job, with Services .DLL like [Export(typeof(IPerson))] public class People : IPerson { ... } that are Lazily detected in a Factory based on public class MyFactory { [ImportMany] IEnumerable<Lazy<IPerson>> m_Crowd; private CompositionContainer m_Container; ... private void Initialized() { var catalog = new AggregateCatalog(); catalog.Catalogs.Add(new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory)); m_Container = new CompositionContainer(catalog); this.m_Container.ComposeParts(this); foreach (Lazy<IPerson> ppl in m_Crowd) { if (ppl != null) { var foo = ppl.Value; ... } } } The Service DLLs are placed on the same folder as the .exe, hence the catalog.Catalogs.Add(new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory)); Everything works fine until we decided to wrap the project in a MSIX package ("Windows Application Packaging Project"). Once the package deployed, there is a crashing Runtime error at line var foo = ppl.Value; --> System.ComponentModel.Composition.CompositionException: The composition produced a single composition error. The root cause is provided bellow. Review the CompositionException.Errors property for more details information. 1) Le fichier de la clé n'a pas été trouvé (pardon my french) Resulting in: The type initializer for 'People' threw an exception Resulting in: An exception occurred when trying to create an instance of type 'People' Resulting in: Cannot activate part 'People' Element: People --> People --> AssemblyCatalog (Assembly="People, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null") Resulting in: Cannot get export 'People' (ContractName="IPerson") --> People --> AssemblyCatalog (Assembly="People, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null") at System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedValueFromComposedPart(ImportEngine engine, ComposablePart part, ExportDefinition definition) at System.ComponentModel.Composition.Hosting.CatalogProvider.GetExportedValue(CatalogPart part, ExportDefinition definition) at System.ComponentModel.Composition.Hosting.CatalogProvider.CatalogExport.GetExportedValueCore() ... at System.Lazy`1.CreateValue() ... (I cannot copy/paste from my working environment, this is a manual, obfuscated transcription) TL;DR: the main program could detect the Service DLL ("Assembly="People, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"") but couldn't dynamically load it. I have a feeling comes from the way MSIX packaged are stored, in a weird C:\Program Files\WindowsApp\Project_1.0.0.0_x64_8wekyajsusuh\Project folder where the laws of catalog.Catalogs.Add(new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory)); would not correctly work. Thanks in advance for any help of this topic!138Views0likes1Comment