Load assemblies without Locking DLLs

Spread the love

Working on a series of scripts that referenced a common DLL I ran into an issue that every instance of the script needed to be stopped and the threads all closed before I could update the code in my Custom DLL.

The code below allows a DLL to be loaded into your scripts without locking the file.  In my case this worked perfectly as various scripts were scheduled and multiple instances could be running at once, the file could be upgraded on the fly and current threads would complete with the version the leaded and the next instance runs with the new version.

$DLLBytes = [System.IO.File]::ReadAllBytes(“MyClassLibrary.dll”)
[System.Reflection.Assembly]::Load($DLLBytes)

 

Leave a Reply

Your email address will not be published. Required fields are marked *