5

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?

P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
  • 1
    "Hack" is a very appropriate term :) "Weird s**t" and "Evil Craziness" also come to mind :) – paulsm4 Jul 03 '12 at 21:57
  • 8
    It's called "Hot Deploy" - see http://stackoverflow.com/questions/2335755/how-to-update-an-assembly-for-a-running-c-sharp-process-aka-hot-deploy – dash Jul 03 '12 at 22:06
  • Many plug-in approaches support this. While for windows' services https://github.com/Topshelf/Topshelf/ supports this. – kenny Jul 03 '12 at 22:14

1 Answers1

3

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.

Jirka Hanika
  • 13,301
  • 3
  • 46
  • 75
  • Can you clarify what you mean by "there be 3+ simultaneous versions"? – P.Brian.Mackey Jul 04 '12 at 13:46
  • @P.Brian.Mackey - Simply attaching an `_old` suffix may not be enough. The suffixes should be dynamic. Version 1 might still be running when you decide to hot deploy version 3 over version 2 and the rename of version 2 would fail. On the other hand, dynamic suffixes will hurt more if your automated mechanism for purging of unused DLLs is unreliable. – Jirka Hanika Jul 04 '12 at 14:04