Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"dynamic operations can only be performed in homogenous appdomain" error while launching PowerShell

I have a powershell script that I am trying to execute from WCF REST service.I am using the System.Management.Automation and System.Management.Automation.Runspaces assemblies.

The C# code looks like this:

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

This error happens here once I try to execute the open statement:

Dynamic operations can only be performed in homogenous AppDomain.

I have looked and looked but nothing worked. I have tried adding this line to my web.config: But it didn't do anything for me.

Do you have thoughts?

like image 676
user1019042 Avatar asked Apr 22 '13 21:04

user1019042


1 Answers

I just googled that error and it seemed to be related to legacyCasPolicy being set to true as discussed here and here. It turns setting it to false resolved your issue as well. Detailed information about this configuration element can be found here.

like image 180
Andy Arismendi Avatar answered Nov 07 '22 14:11

Andy Arismendi