我有四个装配,相互引用,如上图所示:

TpProjectModel共享接口,DILib和FileProject实现它们,并且TpPtojektCLI根据配置文件中的设置使用其中一个实现

当我想在TpProjectCLI中组合它们时,我有以下异常:

组成保持不变 . 由于以下错误,更改被拒绝:组合产生单个组合错误 . 根本原因如下 . 查看CompositionException.Errors属性以获取更多详细信息 . 1)找到多个匹配约束的导出:ContractName TpProjectModel.Reflection.IReflector RequiredTypeIdentity TpProjectModel.Reflection.IReflector导致:无法设置导入'ViewModels.Dashboard.DashboardViewModel.Reflector(ContractName =“TpProjectModel.Reflection.IReflector”) '部分'ViewModels.Dashboard.DashboardViewModel' . 元素:ViewModels.Dashboard.DashboardViewModel.Reflector(ContractName =“TpProjectModel.Reflection.IReflector”) - > ViewModels.Dashboard.DashboardViewModel

代码我如何获得所有需要的程序集:

NameValueCollection plugins = (NameValueCollection)ConfigurationManager.GetSection("plugins");
string[] pluginsCatalogs = plugins.AllKeys;
List<DirectoryCatalog> assemblyCatalogs = new List<DirectoryCatalog>();

foreach (string pluginsCatalog in pluginsCatalogs)
{
    if (Directory.Exists(pluginsCatalog))
        assemblyCatalogs.Add(new DirectoryCatalog(pluginsCatalog));
}

AggregateCatalog catalog = new AggregateCatalog(assemblyCatalogs);
CompositionContainer container = new CompositionContainer(catalog);

try
{
    container.ComposeParts(this);
}
catch (CompositionException compositionException)
{
    Console.WriteLine(compositionException.ToString());
    throw;
}
catch (Exception exception) when (exception is ReflectionTypeLoadException)
{
    ReflectionTypeLoadException typeLoadException = (ReflectionTypeLoadException)exception;
    Exception[] loaderExceptions = typeLoadException.LoaderExceptions;
    loaderExceptions.ToList().ForEach(ex => Console.WriteLine(ex.StackTrace));

    throw;
}