I have the problem that I want to import types from a module dictionary. But because of the plugin based modularity some imports may fail.
But if only one import fails, nothing gets imported - which is certainly not wanted.
try
{
// Use the binary directory
var catalog = new DirectoryCatalog(AssemblyDirectory);
var container = new CompositionContainer(catalog);
// Build the composition batch
var compositionBatch = new CompositionBatch();
compositionBatch.AddPart(this); // for discovering modules
// Compose everything
container.Compose(compositionBatch);
}
catch (ReflectionTypeLoadException loadException)
{
// Nothing will be done here
}
The correct and wanted behavior would be, that all matching types shall be imported, but the failing gets ignored.
How can I accomplish that? Thanks in advance
This answer has an example of how to ignore failed assemblies. You get a list of the assemblies from the directory you're using, and then create an AssemblyCatalog for each, force the error as described here, and then place the catalogs that didn't fail into an AggregateCatalog.