我想加载4个程序集,目前我以如下方式加载它们:
Add-Type -Path 'C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SqlServer.ManagedDTS\v4.0_15.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.ManagedDTS.dll';
Add-Type -Path 'C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SqlServer.DTSPipelineWrap\v4.0_15.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.DTSPipelineWrap.dll';
Add-Type -Path 'C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SqlServer.PipelineHost\v4.0_15.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.PipelineHost.dll';
Add-Type -path 'C:\Windows\Microsoft.NET\assembly\GAC_64\Microsoft.SqlServer.DTSRuntimeWrap\v4.0_15.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.DTSRuntimeWrap.dll'当我试图像这样装载它们时:
Add-Type -AssemblyName Microsoft.SqlServer.ManagedDTS, Microsoft.SqlServer.PipelineHost, Microsoft.SqlServer.DTSRuntimeWrap, Microsoft.SqlServer.DTSPipelineWrap我得到以下错误:
Add-Type : Cannot add type. The assembly 'Microsoft.SqlServer.ManagedDTS' could not be found.
At line:1 char:1
+ Add-Type -AssemblyName Microsoft.SqlServer.ManagedDTS, Microsoft.SqlS ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.SqlServer.ManagedDTS:String) [Add-Type], Exception
+ FullyQualifiedErrorId : ASSEMBLY_NOT_FOUND,Microsoft.PowerShell.Commands.AddTypeCommand如果我只尝试加载一个程序集:
Add-Type -AssemblyName Microsoft.SqlServer.ManagedDTS现在有两条错误消息:
Add-Type : Cannot add type. The assembly 'Microsoft.SqlServer.ManagedDTS' could not be found.
At line:1 char:1
+ Add-Type -AssemblyName Microsoft.SqlServer.ManagedDTS
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.SqlServer.ManagedDTS:String) [Add-Type], Exception
+ FullyQualifiedErrorId : ASSEMBLY_NOT_FOUND,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : Cannot add type. One or more required assemblies are missing.
At line:1 char:1
+ Add-Type -AssemblyName Microsoft.SqlServer.ManagedDTS
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
+ FullyQualifiedErrorId : ASSEMBLY_LOAD_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand发布于 2022-03-18 22:10:26
也许这会有帮助。
If ($host.Name -eq 'ConsoleHost' -or
$host.Name -eq 'Visual Studio Code Host') {
try{ <#+------------------------------------------------+
| Check that the proper assemblies are loaded |
| Required for PS Console and Visual Code, while |
| only Systems.Windows.Forms needed for PSISE! |
+------------------------------------------------+
#>
$ATArgs = @{AssemblyName = "PresentationCore",
"PresentationFramework",
"WindowsBase"
ErrorAction = 'Stop'}
Add-Type @ATArgs
}
catch {
Write-Host $("Failed to load Windows Presentation Framework" +
" and/or other assemblies required for this program!")
Exit
}
} #End If ($host…我在使用基于XAML的菜单的所有脚本中都包含了这段代码,以确保在运行时加载所有必要的程序集,而在使用VSCode或PS时通常不是必需的。
https://stackoverflow.com/questions/71532634
复制相似问题