启动PowerShell时,“动态操作只能在同源appdomain中执行”错误

时间:2013-04-22 21:44:33

标签: powershell automation code-access-security

我有一个PowerShell脚本,我试图从WCF REST服务执行。我正在使用System.Management.AutomationSystem.Management.Automation.Runspaces程序集。

C#代码如下所示:

Command command = new Command(path);
command.Parameters.Add(param);
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
using (Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration))
{
    runspace.Open();
    ... other code
}

一旦我尝试执行open语句,就会发生此错误:

  

动态操作只能在同质AppDomain中执行。

我看了看,但没有任何效果。我尝试将此行添加到我的web.config:   但它对我没有任何作用。

你有想法吗?

1 个答案:

答案 0 :(得分:11)

我只是用谷歌搜索了这个错误,似乎与legacyCasPolicy被设置为真有关,如herehere所述。它将其设置为false也解决了您的问题。有关此配置元素的详细信息,请参见here