15

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?

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
user1019042
  • 2,428
  • 9
  • 43
  • 85
  • 2
    What is `legacyCasPolicy` in the config set to? Also does `NetFx40_LegacySecurityPolicy` exist? – Andy Arismendi Apr 22 '13 at 21:48
  • 3
    awesome!! Adding what you said fixed the issue. Now, I have those web.config setup like this: Please make it a solution, so I mark it. – user1019042 Apr 23 '13 at 01:32
  • 2
    The German error term is "**Dynamische Vorgänge können nur in einer homogenen AppDomain durchgeführt werden.**", just in case someone is googling this. – Uwe Keim Feb 06 '14 at 07:12

1 Answers1

13

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.

Community
  • 1
  • 1
Andy Arismendi
  • 50,577
  • 16
  • 107
  • 124
  • As far as I see, you should now use `legacyCasModel` instead of `legacyCasPolicy`. The referenced SO threads mention it as well. – pholpar Mar 08 '22 at 22:06