简体   繁体   English

C#中的PowerShell:无法加载DLL wldp.dll

[英]PowerShell in C#: Unable to load DLL wldp.dll

I am getting an error when attempting to run the following in C#. 尝试在C#中运行以下命令时出现错误。

The error is: 错误是:

Exception:Thrown Unable to load DLL wldp.dll 异常:抛出无法加载DLL wldp.dll

PowerShell ps = PowerShell.Create();
ps.AddCommand("Get-BrokerSession");
ps.AddParameter("AdminAddress");
ps.AddParameter("MYSERVERNAMEHERE");
Collection<PSObject> psr = ps.Invoke();

It's also saying that Get-BrokerSession is not a recognized command, yet I can use this at the PS command prompt without issue. 也是说Get-BrokerSession不是公认的命令,但是我可以在PS命令提示符下使用它而不会出现问题。

It could be that you have to load the Citrix-specific PowerShell modules. 可能是您必须加载Citrix特定的PowerShell模块。 if your PS version is 3.0. 如果您的PS版本是3.0。 this should resolve error: Get-BrokerSession is not a recognized command 这应该可以解决错误: Get-BrokerSession不是可识别的命令
then you can move to the next step. 那么您可以转到下一步。

InitialSessionState initial = InitialSessionState.CreateDefault();
initial.ImportPSModule(new string[] { @"C:\Temp\PSModule.psm1" });  // + Include in your PSModule.psm1: function ImportCitrixModule { Asnp Citrix* }
Runspace runspace = RunspaceFactory.CreateRunspace(initial);
initial.ThrowOnRunspaceOpenError = true;
runspace.Open();
RunspaceInvoke runSpaceInvoker = new  RunspaceInvoke(runspace); 
runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted");

PowerShell ps = PowerShell.Create();
ps.Runspace = runspace;
ps.AddCommand("ImportCitrixModule"); // +
Collection<PSObject> psr = ps.Invoke();

According to this blog post it can help to check Prefer 32-bit in the project build settings. 根据此博客文章,它可以帮助检查项目构建设置中的“首选32位”。

I ran into this error when trying to start an executable file via C# Powershell in a UnitTest project. 尝试通过UnitTest项目中的C#Powershell启动可执行文件时遇到此错误。 You cannot select this option for UnitTest projects (so it didn't help me) but running my test without debugging it works as intended. 您不能为UnitTest项目选择此选项(因此对我没有帮助),但是在不调试的情况下运行测试可以按预期工作。 I ended up not having a UnitTest/IntegrationTest... 我最终没有UnitTest / IntegrationTest ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM