Tag: mmc

在不同的AppDomain中加载/卸载程序集

我需要在运行时加载的程序集中执行一个方法。 现在我想在方法调用后卸载那些已加载的程序集。 我知道我需要一个新的AppDomain,所以我可以卸载库。 但在这里,出现了问题。 要加载的程序集是我的插件框架中的插件。 他们根本没有切入点。 我所知道的是它们包含一些实现给定接口的类型。 旧的非AppDomain代码看起来像这样(稍微缩短): try { string path = Path.GetFullPath(“C:\library.dll”); AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; Assembly asm = Assembly.LoadFrom(path); Type[] types = asm.GetExportedTypes(); foreach (Type t in types) { if ((t.GetInterface(“IStarter”) != null) && !t.IsAbstract) { object tempObj = Activator.CreateInstance(t); MethodInfo info = t.GetMethod(“GetParameters”); if (info != null) { return info.Invoke(tempObj, null) as […]