Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to rename and copy an assembly?

Tags:

c#

.net

windows

I recently discovered that one can copy over an assembly that is in use by renaming the file and then performing the copy. E.G.

C:\Folder\MyLibrary.dll
=> rename to C:\Folder\MyLibrary.dll_old
=> copy new version C:\Folder\MyLibrary.dll (v2.0)

I was told that the next time the application starts, it will loadup this new assembly. And while the application continues to run, it will continue to use the old assembly (even though it's renamed _old).

Seems like a hack to me. Is it safe to update assemblies in this manner?

like image 707
P.Brian.Mackey Avatar asked Oct 23 '22 17:10

P.Brian.Mackey


1 Answers

It is safe. As long as the old assembly stays loaded, the same app domain will not be attempting to load it again. The file name is not important for continued execution of the app.

However, in production use you would probably have to think about 3+ simultaneous versions and a mechanism to remove the unused files eventually.

like image 142
Jirka Hanika Avatar answered Oct 27 '22 11:10

Jirka Hanika