[英]Using Runspace Factory for Powershell Gives Error
I'm getting the following error on this using line below, I've never seen it up until I started at this new company.我在使用下面的行时收到以下错误,直到我在这家新公司开始工作之前我从未见过它。
System.PlatformNotSupportedException: ReflectionOnly loading is not supported on this platform.
System.PlatformNotSupportedException:此平台不支持 ReflectionOnly 加载。
at System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile)在 System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile)
at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadMshSnapinAssembly(PSSnapInInfo mshsnapinInfo)在 System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadMshSnapinAssembly(PSSnapInInfo mshsnapinInfo)
Error occurs right AT the using statement.错误发生在 using 语句中。 I'm using Visual Studio 2017 on Windows 2008 R2.
我在 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();
}
Turns out that powershell runspace factory does not support .NET Core applications.事实证明,powershell 运行空间工厂不支持 .NET Core 应用程序。 I had to recreate my application using the normal .NET Framework 4.7.1.
我不得不使用普通的 .NET Framework 4.7.1 重新创建我的应用程序。
我不知道这个包是否比您的问题更新,但 2020 年的正确答案是坚持使用 dotnet 核心并使用正确的包。
dotnet add package Microsoft.PowerShell.SDK
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.