应用程序使用的DLL热卸载/重装

编程入门 行业动态 更新时间:2024-10-22 14:01:38
本文介绍了应用程序使用的DLL热卸载/重装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有加载DLL执行处理的特定部分应用

I have an application that loads a DLL to execute a specific part of processing

Example : "Application.dll" loading "Process.dll"

Process.dll动态加载在运行,使用反射,而不是在应用程序中引用。

Process.dll is dynamically loaded at Runtime, using reflection, and not referenced in the application.

处理结束后,将DLL需要在服务器上进行重新编译和稍后重新装回。结果为了做到这一点,我需要释放,否则我得到以下信息:无法复制文件Process.dll到Process.dll该进程无法因为它正被另一个进程访问文件Process.dll'。

After processing is finished, the DLL needs to be recompiled on server and loaded back again later. In order to do so, I need to free it, otherwise I get the following message : "Unable to copy file "Process.dll" to "Process.dll". The process cannot access the file 'Process.dll' because it is being used by another process."

所以,问题是:如何以编程方式免费/发行/再次装入之前,从我的应用程序卸载 Process.dll 。当然,整点就是做这个的无停止应用程序。

So the question is : How to programmatically free/release/unload the Process.dll from my application before loading it back again. Of course,the whole point is to do this WITHOUT stopping the Application.

编辑1:

一个提出的解决方案是这样的:

A proposed solution goes like this :

AppDomain newDomain4Process = AppDomain.CreateDomain("newDomain4Process"); Assembly processLibrary = newDomain4Process.Load("Process.dll"); AppDomain.Unload(newDomain4Process);

我仍然有问题是,虽然我给正确的完整路径,我收到了 FileNotFound异常。这个问题的答案this帖子没有预期的效果无论是。

The problem I am still having is that, though I am giving the proper full path, I get a FileNotFound Exception. The answer to this post did not have the expected effect either.

编辑2:

This帖子救了我的生活,这里是code:

This post saved my life, here is the code :

class ProxyDomain : MarshalByRefObject { public Assembly GetAssembly(string AssemblyPath) { try { return Assembly.LoadFrom(AssemblyPath); } catch (Exception ex) { throw ex; } } } ProxyDomain pd = new ProxyDomain(); Assembly a = pd.GetAssembly(FullDLLPath);

修改3:结果我没有访问的AppDomain并与previous的解决方案,虽然其卸载。当我使用的AppDomain创作的经典方法,我觉得到阿列克谢的警告: AppDomain.Unload 似乎工作,但大会仍然加载(模块视图)。所以,我仍然有我的问题,在某种程度上,因为我真的不能有效卸载DLL。

EDIT 3 : I didn't get access to the AppDomain and unload it with the previous solution though. When I used the classic method of AppDomain Creation, I felt into Alexei's warning : AppDomain.Unload "seemed" to work, but the assembly was still loaded (Module View). So I still have my problem in some way, since I can't really unload the DLL efficiently.

推荐答案

它已经相当一段时间,因为我看着这一点,但我相当肯定,你需要创建一个新的AppDomain 然后加载里面的DLL。

It's been quite a while since I looked at this but I'm fairly sure that you'd need to create a new AppDomain and then load the DLL inside there.

原因是,你不能卸载的大会由它的自我,但你可以卸载一个的AppDomain 的包含大会。

The reason is that you can't unload an Assembly by it self but you can unload an AppDomain that contains an Assembly.

下面是描述如何做到这一点$ C $的CProject文章:要卸载,运行DLL

Here's a CodeProject article that describes how to do this: To Unload a Running Dll

更多推荐

应用程序使用的DLL热卸载/重装

本文发布于:2023-11-09 05:47:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571539.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重装   应用程序   DLL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!