Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Add-Type -Path locking file

Tags:

powershell

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?

like image 777
killercowuk Avatar asked Mar 14 '18 12:03

killercowuk


Video Answer


1 Answers

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?

like image 52
Martin Brandl Avatar answered Nov 21 '22 10:11

Martin Brandl