当我尝试从PowerShell远程会话运行程序集时出现此错误
Could not load file or assembly 'System.Xml.Linq, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find
the file specified.
我通过
启动了远程会话Enter-PsSession -ComputerName myComputer -ConfigurationName Microsoft.Powershell
-Credential domain\user
但是当我在同一台机器上运行它时,它没有任何问题。
更新
我想做点什么
if (Test-Path $AssemblyPath) {
$fileStream = ([System.IO.FileInfo] (Get-Item $AssemblyPath)).OpenRead()
$assemblyBytes = New-Object byte[] $fileStream.Length
$fileStream.Read($assemblyBytes, 0, $fileStream.Length) | Out-Null
$fileStream.Close()
$assemblyLoaded = [System.Reflection.Assembly]::Load($assemblyBytes) | Out-Null
$myObject = New-Object namespaceInMyAssembly.ClassInMyAssembly
$myObject.doMyAction()
}
答案 0 :(得分:1)
我发现了问题: 我的Powershell已在powershell.exe.config中配置为.Net 4,但未在wsmprovhost.exe.config中配置。所以我无法从远程会话加载.Net 4程序集。另请参阅this question。