启动PowerShell时"dynamic operations can only be performed in homogenous appdomain"错误



我有一个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:但它对我没有任何帮助。

你有想法吗?

我只是在谷歌上搜索了这个错误,它似乎与legacyCasPolicy被设置为true有关,如这里和这里所讨论的。将其设置为false也可以解决您的问题。关于这个配置元素的详细信息可以在这里找到。

最新更新