Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 29-Nov-15 17:30pm
v2
Comments
PIEBALDconsult 29-Nov-15 23:47pm    
Nope.
Sergey Alexandrovich Kryukov 30-Nov-15 1:15am    
Well, right, this is impossible as such. But something fairly similar is still possible: one can use multiple application domains, unload the whole AppDomain, and later reload it with replaced assembly, which also requires using reflection. This is not so simple, but quite doable. Please see Solution 2.
—SA
Krunal Rohit 30-Nov-15 0:42am    
Nah.

-KR
Sergey Alexandrovich Kryukov 30-Nov-15 1:15am    
Well, right, this is impossible as such. But something fairly similar is still possible: one can use multiple application domains, unload the whole AppDomain, and later reload it with replaced assembly, which also requires using reflection. This is not so simple, but quite doable. Please see Solution 2.
—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
 
Share this answer
 
v2
 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.


[Reference^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900