From 7476e0331979d6f7768e964caf47c91c0e07cb72 Mon Sep 17 00:00:00 2001 From: GraceSolutions Date: Tue, 15 Apr 2025 01:04:29 -0400 Subject: [PATCH] Update PSM1 files to use Add-Type instead of Assembly.Load --- output/PSOPNSenseAPI/PSOPNSenseAPI.psm1 | 43 +++++---------------- output/PSOPNSenseAPI/lib/PSOPNSenseAPI.dll | Bin 534016 -> 534016 bytes src/PSOPNSenseAPI/PSOPNSenseAPI.psm1 | 43 +++++---------------- 3 files changed, 20 insertions(+), 66 deletions(-) diff --git a/output/PSOPNSenseAPI/PSOPNSenseAPI.psm1 b/output/PSOPNSenseAPI/PSOPNSenseAPI.psm1 index 05f4dcf..d4b84da 100644 --- a/output/PSOPNSenseAPI/PSOPNSenseAPI.psm1 +++ b/output/PSOPNSenseAPI/PSOPNSenseAPI.psm1 @@ -1,36 +1,13 @@ -# Load assemblies from the lib folder using System.Reflection.Assembly::LoadBytes -# This avoids file lock issues when the module is loaded +# Load the main assembly directly +$mainDllPath = Join-Path $PSScriptRoot "lib\PSOPNSenseAPI.dll" -$libPath = Join-Path $PSScriptRoot -ChildPath "lib" +Write-Verbose "Loading assembly from $mainDllPath" -$DLLFileList = Get-ChildItem -Path $libPath -Filter "*.dll" - -$DLLFileListCount = ($DLLFileList | Measure-Object).Count - -$DLLFileListCounter = 1 - -For ($DLLFileListIndex = 0; $DLLFileListIndex -lt $DLLFileListCount; $DLLFileListIndex++) - { - Try - { - $DLLFile = $DLLFileList[$DLLFileListIndex] - - Write-Verbose "Attempting to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount). Please Wait..." - - Write-Verbose "Path: $($DLLFile)" - - $DLLFileBytes = [System.IO.File]::ReadAllBytes($DLLFile.FullName) - - $Null = [System.Reflection.Assembly]::Load($DLLFileBytes) - - Write-Verbose "Successfully loaded DLL assembly $($DLLFileListCounter) of $($DLLFileListCount)" - } - Catch - { - Write-Warning "Failed to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount): $($_.Exception.Message)" - } - Finally - { - $DLLFileListCounter++ - } +try { + Add-Type -Path $mainDllPath + Write-Verbose "Successfully loaded assembly from $mainDllPath" +} catch { + $errorMessage = $_.Exception.Message + Write-Error "Failed to load assembly from $($mainDllPath): $($errorMessage)" + throw } diff --git a/output/PSOPNSenseAPI/lib/PSOPNSenseAPI.dll b/output/PSOPNSenseAPI/lib/PSOPNSenseAPI.dll index 4d100e124869e9ed3150dc7c7f866b6ec0436f3a..dd1d394379122fb5c5805c2f8d334f34b0021103 100644 GIT binary patch delta 262 zcmZoTqtI|hVL}IsnOWVN#-7$5#?~ID)*j~89+uV~)~!8kTb>HM5}3`nvUsCYOB!FM zGh2hj_JC(>(cK#6iAKi8hDmAWCPrzgNrs6jN#-dQsfLCY$%f_zrWR&qDalEe$%&TR zFBh^0u41Y9-2H31h73o5z;nH#kH#0=d>399ZWQU-DKNc5h9g4(CaMS(1*u;cGgsVdstd~Shx1DZFwr-w{V8rLz_0gRs8in zJzO6(wg)_8i|*DivNSX^Gqg-fGqyA^v`jNjHL|cUF)}hrF-$eLNHj^aGzZFACZ}w_ zT*w}{ily(5Qp0o&8IAyfw6gE#_bF{~*cH9W0;EAO1t^os cU=9>X1d62r)tW=~Su!Luq-^h2;wWVX0OQY9Z~y=R diff --git a/src/PSOPNSenseAPI/PSOPNSenseAPI.psm1 b/src/PSOPNSenseAPI/PSOPNSenseAPI.psm1 index 05f4dcf..d4b84da 100644 --- a/src/PSOPNSenseAPI/PSOPNSenseAPI.psm1 +++ b/src/PSOPNSenseAPI/PSOPNSenseAPI.psm1 @@ -1,36 +1,13 @@ -# Load assemblies from the lib folder using System.Reflection.Assembly::LoadBytes -# This avoids file lock issues when the module is loaded +# Load the main assembly directly +$mainDllPath = Join-Path $PSScriptRoot "lib\PSOPNSenseAPI.dll" -$libPath = Join-Path $PSScriptRoot -ChildPath "lib" +Write-Verbose "Loading assembly from $mainDllPath" -$DLLFileList = Get-ChildItem -Path $libPath -Filter "*.dll" - -$DLLFileListCount = ($DLLFileList | Measure-Object).Count - -$DLLFileListCounter = 1 - -For ($DLLFileListIndex = 0; $DLLFileListIndex -lt $DLLFileListCount; $DLLFileListIndex++) - { - Try - { - $DLLFile = $DLLFileList[$DLLFileListIndex] - - Write-Verbose "Attempting to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount). Please Wait..." - - Write-Verbose "Path: $($DLLFile)" - - $DLLFileBytes = [System.IO.File]::ReadAllBytes($DLLFile.FullName) - - $Null = [System.Reflection.Assembly]::Load($DLLFileBytes) - - Write-Verbose "Successfully loaded DLL assembly $($DLLFileListCounter) of $($DLLFileListCount)" - } - Catch - { - Write-Warning "Failed to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount): $($_.Exception.Message)" - } - Finally - { - $DLLFileListCounter++ - } +try { + Add-Type -Path $mainDllPath + Write-Verbose "Successfully loaded assembly from $mainDllPath" +} catch { + $errorMessage = $_.Exception.Message + Write-Error "Failed to load assembly from $($mainDllPath): $($errorMessage)" + throw }