Reputation: 4623
I'm running into an odd problem with MEF's composition container and directory catalog where I pass in a full path to a folder containing assemblies:
In C:\Program Files\MyCompany\MyApp\Bin
AssemblyA: ExportedTypeA, ExportedTypeB
AssemblyB: BaseExportedTypeA, BaseExportedTypeB
Executed from another location (C:\users\Me\dev\project\foo\bar\bar2\bin\debug\OtherApp.Exe)
In the application I call:
string ProviderPhysicalPath = @"C:\Program Files\MyCompany\MyApp\Bin";
using (DirectoryCatalog catalog = new DirectoryCatalog(ProviderPhysicalPath))
using (CompositionContainer container = new CompositionContainer(catalog))
{
container.ComposeParts(this);
}
On container.ComposeParts(this)
I get the following exception:
The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) Could not find a part of the path 'C:\USERS\Me\dev\project\foo\bar\bar2\BIN\DEBUG\BIN\'.
What's confusing is two parts:
Is there something I'm doing wrong?
Upvotes: 1
Views: 1147
Reputation: 12795
You might be running into this problem:
When using a DirectoryCatalog or passing a path to the AssemblyCatalog constructor, MEF will attempt to load assemblies in the default load context. However, if the assemblies are not in the probing path or the GAC, this will not be possible, and MEF will load them in the load-from context instead.
@"C:\Program Files\MyCompany\MyApp\Bin"
might not be in the probing path. I can't say I have experienced the issue or explored it much. See Daniel Plaisted's Blog for details, scroll down to the section 'Assembly Load Issues'
How to Debug and Diagnose MEF Failures
Upvotes: 1