【发布时间】:2020-07-13 17:51:35
【问题描述】:
我在使用下面的行时收到以下错误,直到我开始在这家新公司工作之前我从未见过它。
System.PlatformNotSupportedException:此平台不支持 ReflectionOnly 加载。
在 System.Reflection.Assembly.ReflectionOnlyLoadFrom(字符串 assemblyFile)
在 System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadMshSnapinAssembly(PSSnapInInfo mshsnapinInfo)
在 using 语句处发生错误。我在 Windows 2008 R2 上使用 Visual Studio 2017。
using (Runspace runspace = RunspaceFactory.CreateRunspace())
{
runspace.Open();
PowerShell ps = PowerShell.Create();
ps.Runspace = runspace;
PSSnapInException psex;
runspace.RunspaceConfiguration.AddPSSnapIn("Citrix*", out psex);
Pipeline pipeline = runspace.CreatePipeline();
Command getSession = new Command("Get-XASession");
getSession.Parameters.Add("-ComputerName", serverName);
getSession.Parameters.Add("-AccountDisplayName", objWINS + "\\" + strUser);
pipeline.Commands.Add(getSession);
Collection<PSObject> output = pipeline.Invoke();
}
【问题讨论】:
-
你引用的是哪个 dll 版本?
-
我不肯定,但我认为 6.1.7601.17515
-
我不知道是谁标记了这个,但很烦人他们没有说明原因。我在谷歌上搜索过这个错误,关于它的信息非常少。如果您在错误周围加上引号,则会出现 4 个不相关的结果。
-
你能提供更多代码吗?你的导入部分有什么
-
我已经添加了更多,但实际上它甚至没有超过 using 语句。
标签: c# powershell