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 4d100e1..dd1d394 100644 Binary files a/output/PSOPNSenseAPI/lib/PSOPNSenseAPI.dll and b/output/PSOPNSenseAPI/lib/PSOPNSenseAPI.dll differ 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 }