客户端使用它时是否可以替换.net dll文件? [英] Is it possible to replace .net dll file while client using it?

查看:71
本文介绍了客户端使用它时是否可以替换.net dll文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个.net dll文件复制到我的服务器,每个客户端都想使用regasm / codebase example.dll以相同的路径注册该dll。现在一切正常,但有时我想在这个dll做一些修改所以我试图替换该DLL但我不能这样做。总是说操作无法完成,因为文件夹或其中的文件在另一个程序中打开消息。我认为有些客户在使用此应用程序时我正在更新它,所以请帮我解决这个问题。

注意:我不想关闭我的客户使用的应用程序。意味着没有关闭应用程序我想这样做。

I copied one .net dll file to my server and every client want to register that dll with the same path using regasm /codebase example.dll. now everything working fine but sometimes i want to do some modification in this dll so i am trying to replace that dll but i cannot do it. always it says "The action can't be completed because the folder or a file in it is open in another program" message. i think some clients are using this application while i am updating it so please help me to solve this problem.
Note: I don't want to close application that which is using by my clients. means without closing application i want to do this.

推荐答案

不,你不能这样做,因为当前加载执行的所有模块都受到操作系统的删除或任何保护修改,由于明显的原因。


但是,你可以做类似的事情。如果使用反射加载程序集,则可以将程序集添加到当前正在运行的进程中。拆卸/更换这种组件也是可能的,但这要困难得多。没有卸载任何已加载的程序集的功能。这样做是出于可靠性的目的。安全地移除组件很困难,因为一些其他组件我仍然引用组件中的一些不再需要的对象,这很难检测到卸载组件的功能在CLR中不可用。



同时,如果程序集在一个单独的应用程序域中加载,则可以间接卸载程序集。您可以使用其所有程序集卸载整个应用程序域。但它会使编程变得更加困难,因为应用程序域彼此隔离以及进程;所有对象都位于独立的隔离地址空间中。跨应用程序域的通信意味着使用IPC。类 System.AppDomain 提供简化的IPC工具,简化了通信,但这仍然不是很简单。



我在过去的答案中解释了与编程方法相关的大部分细节。我在这一篇中引用了它们:访问驻留在插件dll中的自定义对象 [ ^ ]。



-SA
No, you cannot do it, because all modules currently loaded for execution are protected by the OS from deletion or any modifications, by apparent reasons.

However, you can do something similar. You can add an assembly to the currently running process if you load it using reflection. Removing/replacing such assembly is also possible, but this is much harder. There is no such functionality as "unloading" of any already loaded assembly. This is done for the purpose of reliability. It's hard to remove the assembly safely, because some other assemblies my still reference some objects in the assembly which is not needed anymore, and this is so hard detect that such functionality as unloading the assembly is not available in CLR.

At the same time, the assembly can be unloaded indirectly, if it is loaded in a separate Application Domain. You can unload the whole application domain, with all its assemblies. But it will make programming considerably harder, because Application Domains are isolated from each other as well as the processes; all objects live in separate isolated address spaces. Communication across application domain means using IPC. The class System.AppDomain provides simplified IPC facility which simplifies the communications, but this is still not quite trivial.

I explained most of the detail relevant to such approach to programming in my past answers. I referenced them in this one: Access a custom object that resides in plug in dll[^].

—SA


 Yes,sometimes necessary to replace a DLL with a newer version. Before replacing a DLL, perform a version check to ensure that you are replacing an older version with a newer version. It is possible to replace a DLL that is in use. The method you use to replace DLLs that are in use depends on the operating system you are using. On Windows XP and later, applications should use Isolated Applications and Side-by-side Assemblies.

It is not necessary to restart the computer if you perform the following steps:

1.Use the MoveFileEx function to rename the DLL being replaced. Do not specify MOVEFILE_COPY_ALLOWED, and make sure the renamed file is on the same volume that contains the original file. You could also simply rename the file in the same directory by giving it a different extension.

2.Copy the new DLL to the directory that contains the renamed DLL. All applications will now use the new DLL.

3.Use MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT to delete the renamed DLL.

NOTE : Before you make this replacement, applications will use the original DLL until it is unloaded. After you make the replacement, applications will use the new DLL. When you write a DLL, you must be careful to ensure that it is prepared for this situation, especially if the DLL maintains global state information or communicates with other services. If the DLL is not prepared for a change in global state information or communication protocols, updating the DLL will require you to restart the computer to ensure that all applications are using the same version of the DLL.





[参考^ ]


这篇关于客户端使用它时是否可以替换.net dll文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆