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

27,094

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.

Share:
27,094
user1019042
Author by

user1019042

Updated on December 24, 2020

Comments

  • user1019042
    user1019042 over 3 years

    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?

    • Andy Arismendi
      Andy Arismendi about 11 years
      What is legacyCasPolicy in the config set to? Also does NetFx40_LegacySecurityPolicy exist?
    • user1019042
      user1019042 about 11 years
      awesome!! Adding what you said fixed the issue. Now, I have those web.config setup like this: <NetFx40_LegacySecurityPolicy enabled="true"/> <trust legacyCasModel="false" level="Full" /> Please make it a solution, so I mark it.
    • Uwe Keim
      Uwe Keim over 10 years
      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.
  • pholpar
    pholpar over 2 years
    As far as I see, you should now use legacyCasModel instead of legacyCasPolicy. The referenced SO threads mention it as well.