Loading all these package dependencies with repetitive try/ catch blocks:
$libPath = ".\packages\DocumentFormat.OpenXml.3.3.0\lib\netstandard2.0"
$libFPath = ".\packages\DocumentFormat.OpenXml.Framework.3.3.0\lib\netstandard2.0"
$libSPath = ".\packages\System.IO.Packaging.8.0.0\lib\netstandard2.0"
$libMPath = ".\packages\System.Memory.4.5.4\lib\netstandard2.0"
$libBPath = ".\packages\System.Buffers.4.5.1\lib\netstandard2.0\System.Buffers.dll"
$libVPath = ".\packages\System.Numerics.Vectors.4.5.0\lib\netstandard2.0\System.Numerics.Vectors.dll"
$libCSPath = ".\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll"
#[System.Reflection.Assembly]::LoadFrom("$memoryPath\System.Memory.dll") | Out-Null
#Write-Host "Loaded: System.Memory.dll"
### Load all DLLs in the folder via reflection
Get-ChildItem -Filter "*.dll" -Path $libBPath | ForEach-Object {
try {
[System.Reflection.Assembly]::LoadFrom($_.FullName) | Out-Null
Write-Host "Loaded: $($_.Name)"
}
catch {
Write-Warning "Failed to load $($_.Name): $($_.Exception.Message)"
}
}
Then I try to open an excel file doing the following:
### Load path to excel file
try {
$excelFile = (Resolve-Path "./excel.xlsx").Path
Write-Host "Path resolved: $excelFile"
}
catch {
Write-Error "The file doesn't exist!"
}
### Load/Open excel file
try{
$doc = [DocumentFormat.OpenXml.Packaging.SpreadsheetDocument]::Open($excelFile, $false)
Write-Host "File opened successfully"
$doc.Close()
}
catch{
Write-Host "Error during excel file processing: $_"
Write-Host "Error during excel file processing .Message : $($_.Exception.Message)"
}
And receiving these exceptions:
Exception calling "Open" with "2" argument(s): "You cannot call a method on a null-valued expression." Error during excel file processing.
Message : Exception calling "Open" with "2" argument(s): "You cannot call a method on a null-valued expression."
Any ideas? Pretty much new to PowerShell.
System.Buffers.dllwith your current code.OpenXmllibrary