I have four assemblies which referencing each others as it is shown in the picture above:
TpProjectModel share interfaces, DILib and FileProject implements them, and TpPtojektCLI uses one of the implemantation depending on settings in config file
When I want to compose them in TpProjectCLI, I have following exception:
The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) More than one export was found that matches the constraint: ContractName TpProjectModel.Reflection.IReflector RequiredTypeIdentity TpProjectModel.Reflection.IReflector
Resulting in: Cannot set import 'ViewModels.Dashboard.DashboardViewModel.Reflector (ContractName="TpProjectModel.Reflection.IReflector")' on part 'ViewModels.Dashboard.DashboardViewModel'. Element: ViewModels.Dashboard.DashboardViewModel.Reflector (ContractName="TpProjectModel.Reflection.IReflector") --> ViewModels.Dashboard.DashboardViewModel
And the code how I'm getting all needed assemblies:
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;
}
Aucun commentaire:
Enregistrer un commentaire