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

use*_*042 14 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
}
Run Code Online (Sandbox Code Playgroud)

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

动态操作只能在同源AppDomain中执行.

我看了看,但没有任何效果.我已经尝试将此行添加到我的web.config:但它没有为我做任何事情.

你有想法吗?

And*_*ndi 12

我只是用谷歌搜索了这个错误,它似乎与legacyCasPolicy设置为真有关,正如这里这里所讨论的那样.它将其设置为false也解决了您的问题.有关此配置元素的详细信息,请参见此处.