Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Application pages and Powerhsell script execution

$
0
0

Hello,

When I try to execute powerhsell in code behind of the application page, I have following error:

{"Dynamic operations can only be performed in homogenous AppDomain."}

   at System.Management.Automation.SessionStateScope..ctor(SessionStateScope parentScope)
   at System.Management.Automation.SessionStateInternal..ctor(SessionStateInternal parent, Boolean linkToGlobal, ExecutionContext context)
   at System.Management.Automation.SessionStateInternal..ctor(ExecutionContext context)
   at System.Management.Automation.ExecutionContext.InitializeCommon(AutomationEngine engine, PSHost hostInterface)
   at System.Management.Automation.ExecutionContext..ctor(AutomationEngine engine, PSHost hostInterface, RunspaceConfiguration runspaceConfiguration)
   at System.Management.Automation.AutomationEngine..ctor(PSHost hostInterface, RunspaceConfiguration runspaceConfiguration, InitialSessionState iss)
   at System.Management.Automation.Runspaces.LocalRunspace.DoOpenHelper()
   at System.Management.Automation.Runspaces.LocalRunspace.OpenHelper(Boolean syncCall)
   at System.Management.Automation.Runspaces.RunspaceBase.CoreOpen(Boolean syncCall)
   at System.Management.Automation.Runspaces.RunspaceBase.Open()
   at GenusMUIntergation.Code.Handlers.UpdateSharepointPhoto.<ProcessRequest>b__0()
   at Microsoft.SharePoint.SPSecurity.CodeToRunElevatedWrapper(Object state)
   at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass5.<RunWithElevatedPrivileges>b__3()
   at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)



Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open(); (at this line of code)
RunspaceInvoke invoker = new RunspaceInvoke(runspace);

Probably this problem related with CAS.

How can I resolve this , and execute powerhsell script in IHttpHandlers or ApplicationPages?

               

Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>