在C#中使用AppDomain动态加载和卸载dll
发布时间:2020-12-15 18:24:28 所属栏目:百科 来源:网络整理
导读:在我的一个与系统诊断相关的应用程序中,相关的DLL将在C#中动态加载和卸载.经过一些搜索后,我发现一个单独的DLL无法动态加载其完整的AppDomain.所以我必须创建一个AppDomain并使用该DLL动态卸载.但我找不到任何地方我如何在代码中使用它.我无法显示应用程序代
在我的一个与系统诊断相关的应用程序中,相关的DLL将在C#中动态加载和卸载.经过一些搜索后,我发现一个单独的DLL无法动态加载其完整的AppDomain.所以我必须创建一个AppDomain并使用该DLL动态卸载.但我找不到任何地方我如何在代码中使用它.我无法显示应用程序代码,因为它违反了公司规则.
有人可以告诉我一些应用程序代码来使用它.我想使用appdomain动态加载和卸载dll并在该dll中调用特定方法,dll没有任何入口点. 谢谢你的回答. 解决方法
How to: Load Assemblies into an Application Domain
public static void Main() { // Use the file name to load the assembly into the current // application domain. Assembly a = Assembly.Load("example"); // Get the type to use. Type myType = a.GetType("Example"); // Get the method to call. MethodInfo myMethod = myType.GetMethod("MethodA"); // Create an instance. object obj = Activator.CreateInstance(myType); // Execute the method. myMethod.Invoke(obj,null); } 至于如何卸载它,你必须卸载AppDomain本身,见this AppDomain Temporary = AppDomain.CreateDomain("Temporary"); try { Gateway Proxy = (Gateway) Temporary.CreateInstanceAndUnwrap("Shim","Shim.Gateway"); Match M = Proxy.LoadAndMatch("Plugin.dll","Though the tough cough and hiccough,plough them through"); } finally { AppDomain.Unload(Temporary); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读