PowerShell | Load assemly the right way


We often want to load an assembly into our environment.
Even though there is not much to it, there are a few ways to achieve it, ones better than others.

So far, I've used:
[void][Reflection.Assembly]::LoadFrom("assembly.dll")


Turns out, using PowerShell or .NET, our used dll may become locked. Even if this is not an issue for us, if we could improve this load to prevent file locks, and prevent future issues.
So we can do that by loading the file strem into the memory, instead of using its file system location.
[void][Reflection.Assembly]::Load([System.IO.File]::ReadAllBytes("assembly.dll"))

Comments

Popular posts from this blog

Breaking down document locking in SharePoint

Document ID not being generated

Working around X-Frame-Options for iframes