PowerShell7加载GAC中SQL Server IntegrationServices程序集报错求助
尝试将用于部署SQL Server Integration Services项目的PowerShell 5脚本迁移到PowerShell 7运行时,遇到全局程序集缓存(GAC)程序集加载失败的问题。
原PowerShell 5可正常运行的代码
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.IntegrationServices")
PowerShell 7执行时的报错信息
MethodInvocationException: E:\Work\temp\load-assembly.ps1:6
Line |
6 | [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Mana .
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "LoadWithPartialName" with "1" argument(s): "Could not load file or assembly
| 'Microsoft.SqlServer.Management.IntegrationServices, Culture=neutral, PublicKeyToken=null'. Operation is not supported.
| (0x80131515)"
已尝试的解决方案
尝试通过指定程序集全名使用Load方法加载,结果与LoadWithPartialName方法一致,仍报错:
$loadStatus = [System.Reflection.Assembly]::Load("Microsoft.SqlServer.Management.IntegrationServices, "+"Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL")
目前不确定该错误是由于Microsoft.SqlServer.Management.IntegrationServices程序集不兼容.NET Core,还是PowerShell Core需要使用不同的程序集加载语法。
内容的提问来源于stack exchange,提问作者sergiom

