I've been using
Add-Type -Path "Path to dll"
for loading .NET assemblies into Powershell (v3) scripts. What I've found is this causes the dll file to become locked until the powershell console is terminated.
Is there some way to prevent this from happening? Can I somehow close or remove my references to release lock on this file at end of my script?
Yes, you can read the dll into memory and load the assembly using reflection:
$bytes = [System.IO.File]::ReadAllBytes($storageAssemblyPath)
[System.Reflection.Assembly]::Load($bytes)
I added this solution as an answer to How to load assemblies in PowerShell?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With