J'ai une fonction comme cellePourquoi tous les DLLs ne sont pas chargés en déroulant
public void SetOperationDropDown()
{
cmbOperations.DataSource = PluginManager.GetAllPlugins();
if(cmbOperations.Items.Count > 0)
{
cmbOperations.SelectedItem = cmbOperations.Items[0];
}
}
Cette fonction doit obtenir le nom de tous les dll
public class PluginManager
{
/// <summary>
/// This function gets the name of the plugins and return that in a List<string>.
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public static List<string> GetAllPlugins()
{
DirectoryInfo objDirectoryInfo = new DirectoryInfo("Plugins");
FileInfo[] args = objDirectoryInfo.GetFiles("*.dll");
List<string> assemblyNames = new List<string>();
Assembly[] oAssemblies = new Assembly[args.Length];
for(int assemblyCount = 0;assemblyCount < args.Length;assemblyCount++)
{
string executablePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
oAssemblies[assemblyCount] = Assembly.LoadFile(executablePath.Remove(0,6) + "\\Plugins\\" + args[assemblyCount].Name);
try
{
foreach(Type oType in oAssemblies[assemblyCount].GetTypes())
{
// Check whether class is inheriting from IMFDBAnalyserPlugin.
if(oType.GetInterface("IMFDBAnalyserPlugin") == typeof(IMFDBAnalyserPlugin))
{
assemblyNames.Add(args[assemblyCount].Name.Substring(args[assemblyCount].Name.LastIndexOf("\\") + 1));
}
}
}
catch(Exception ex)
{
EventLog log = new EventLog("Application");
log.Source = "MFDBAnalyser";
log.WriteEntry(ex.Message);
}
}
// Passing data one application domain to another.
AppDomain.CurrentDomain.SetData("AssemblyNames", assemblyNames.ToArray());
return assemblyNames;
}
et doivent être placés dans la liste déroulante quand ils sont retournés ici
//Checks for the selectedItem in the cmbOpearions dropdown and make call to appropriate functions.
string assemblyName = Convert.ToString(cmbOperations.SelectedValue);
Assembly assembly = Assembly.LoadFrom(assemblyName);
int fileExtensionPos = assemblyName.LastIndexOf(".");
string fileName = assemblyName.Substring(0, fileExtensionPos);
Type localType = assembly.GetType(fileName + "." + fileName);
Mais il ne reçoit pas tous les dll créés à partir de cette façon
Type localType = assembly.GetType(fileName + "." + fileName);
J'ai besoin de charger la liste complète des DLL dans la liste déroulante.
Où je vais mal ???
Quels événements sont enregistrées par l'intermédiaire de votre gestionnaire d'exceptions? –