Forum Discussion
MEF'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))] |
that are Lazily detected in a Factory based on
public class MyFactory |
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. (pardon my french) Resulting in: The type initializer for 'People' threw an exception |
(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!
1 Reply
You are using some things I don't have experience with, but I can suggest that you try a sxstrace against the run to see what .Net tells you about the failure to load. A ProcessMonitor trace might also be helpful, but start with the sxstrace.
I don't think there is anything in running in the MSIX container that should interfere with your code, unless the exe is not at the root of the package. When running inside the container the working directory of the exe is the C:\Windows\System32 folder and not the folder of the exe. In that case, the simplest solution would be either to place the dlls in the root folder, or under a VFS\SystemX64 (or VFS\SystemX86 if 32bit) folder. MSIX will always find the dlls if there.
Tim