I can import MEF assemblies into my host application. However, when the Imported assembly has other dependencies, e.g. other external assemblies, I get a ReflectionTypeLoadException.
I don't think I should have to reference external dependencies in my host project but cannot see how to get these external dependencies to resolve/load.
The Imports are retrieved using a DirectoryCatalog where I have the Import-annotated assemblies. I have tried adding the external dependency assemblies into the folder as well but that doesn't seem to get me anywhere. Here is the code:
var catalog = new DirectoryCatalog(assemblyLocation);
var container = new CompositionContainer(catalog);
var pluginRepo = new PluginRepository()
{
TestAdaptors = container.GetExportedValues<ITestAdaptor>()
};
foreach (var testAdaptor in pluginRepo.TestAdaptors)
{
testAdaptor.Execute();
}
Is there a different approach I should use? How can I get these external dependencies to load?
It turned out that yes, I can place all of the external assemblies in the folder with the Import-annotated assemblies and they are correctly loaded and therefore I don't have to reference these external dependencies in my host project.
The problem was that the test project I was given had some spurious, unused assemblies which were failing due to missing dependencies. (Yet another reminder of why a build server is your best friend!).
However, we are at the early stage of development of this so issues like this can be expected.