/// <summary> /// Returns the strong name of passed assembly if it is has a sign; /// otherwise returns null. /// </summary> /// <param name="assembly">The assembly that strong name the method will return.</param> /// <returns>The strong name of passed assembly if it is has a sign; /// otherwise returns null.</returns> private static StrongName GetStrongName(Assembly assembly) { AssemblyName assemblyName = assembly.GetName(); byte[] publicKey = assemblyName.GetPublicKey(); if (publicKey == null || publicKey.Length == 0) { OnNotLoaded?.Invoke(assemblyName.Name); return(null); } StrongNamePublicKeyBlob keyBlob = new StrongNamePublicKeyBlob(publicKey); return(new StrongName(keyBlob, assemblyName.Name, assemblyName.Version)); }
/// <summary> /// Adds signed plugins to this <see cref="AggregateCatalog"/>. /// </summary> /// <param name="ac">A catalog that will contain signed plugins.</param> /// <param name="dc">A catalog with all available plugins.</param> private static void AddSignedPlugins(AggregateCatalog ac, DirectoryCatalog dc) { foreach (string assemblyPath in dc.LoadedFiles) { StrongName assemblyStrongName = GetStrongName(Assembly.LoadFile(assemblyPath)); if (assemblyStrongName == null) { continue; } if (assemblyStrongName.PublicKey.Equals(ThisAppStrongName.PublicKey)) { AssemblyCatalog plugin = new AssemblyCatalog(assemblyPath); //string types = string.Empty; //string interfaces = string.Empty; //foreach (Type type in pluginAc.Assembly.GetTypes()) //{ // foreach (Type interf in type.GetInterfaces()) // { // interfaces += interf.ToString(); // } // types += type.BaseType.ToString(); //} //MessageBox.Show( // types + '\n' + interfaces, // "Type of DLL", // MessageBoxButtons.OK, // MessageBoxIcon.Information); // aggrCatalog.Catalogs.Contains(...)) - not working. if (!IsAlreadyLoaded(ac, plugin)) { ac.Catalogs.Add(plugin); OnLoaded?.Invoke(assemblyStrongName.Name); } } else { OnNotLoaded?.Invoke(assemblyStrongName.Name); } } }