Again the topic of MEF not loading plugins correctly..
First of all: I took the last 7 hours searching similar questions and trying to apply the solutions given there, but I couldn't find any solution that worked for me.
Here is the Situation: Main application using 3 classes
- Main class with GUI ( Windows forms )
- Export class with Interface IMain for the PLugIns being able to give messages to the main window
- Import class that loads all available Plugins from a given Directory
All this worked like a charm for one directory, where all the Plugins were stored. Now my superiors wanted me to rework it, so that every Plugin gets its own subdirectory within the main plugin Directory. And that's were the trouble began. I tried modifying my Code to get this Task done but now all the Plugins are loaded into the Catalogs but are missing in the list, from where I can call them through the applications GUI.
Here the code snippet from my Import class:
public class ServiceTool
{
CompositionContainer ComContainer;
[ImportMany(typeof(Interfaces.IPlugIn))]
public List<Interfaces.IPlugIn> Liste = new List<Interfaces.IPlugIn>();
public ServiceTool()
{
ModuleSuchen();
MessageBox.Show(Liste.Count.ToString());
}
void ModuleSuchen()
{
var AggKatalog = new AggregateCatalog();
var Dlls = Directory.GetFiles("D:\\Automation\\TIA\\FER-ServiceTool\\PlugIns", "*.dll", SearchOption.AllDirectories);
foreach(var DllDatei in Dlls)
{
try
{
AggKatalog.Catalogs.Add(new AssemblyCatalog(Assembly.LoadFile(DllDatei)));
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
}
ComContainer = new CompositionContainer(AggKatalog);
try
{
this.ComContainer.ComposeParts(this);
}
catch (CompositionException ComEx)
{
var ComExceptions = ComEx.Errors;
foreach (var ComException in ComExceptions)
{
MessageBox.Show(ComException.ToString());
}
}
catch (ReflectionTypeLoadException RTLEx)
{
Exception[] Exceptions = RTLEx.LoaderExceptions;
foreach (Exception Ex in Exceptions)
{
MessageBox.Show(Ex.ToString());
}
}
}
}
Where is the problem loading the plugins from the subdirectories? I'm just a beginner in programming and I have absolutely no clue why it isn't working anymore..