Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding Powershell v2.0 in .NET app on Windows 8 RTM

Tags:

Im getting the following error when trying to run hosted powershell scripts before upgrading from Windows 7 I never got this error.

The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(2977) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject. Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(2984) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject. Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(2991) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject. Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(2998) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject. Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3005) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.

I have applied the following in App.config:

<dependentAssembly>   <assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />   <publisherPolicy apply="no" /> </dependentAssembly> 

What could the issue be?

like image 838
keyoke Avatar asked Sep 28 '12 10:09

keyoke


People also ask

How do I know if PowerShell v2 is installed?

Open "PowerShell". Enter "Get-WindowsFeature | Where Name -eq PowerShell-v2". If "Installed State" is "Installed", this is a finding.

How do I run PowerShell v2?

To start Windows PowerShell with the Windows PowerShell 2.0 Engine, use the Version parameter of PowerShell.exe . You can run the command at any command prompt, including Windows PowerShell and Cmd.exe.

What is PowerShell v2?

PowerShell v2 includes changes to the scripting language and hosting API, in addition to including more than 240 new cmdlets. New features of PowerShell 2.0 include: PowerShell remoting: Using WS-Management, PowerShell 2.0 allows scripts and cmdlets to be invoked on a remote machine or a large set of remote machines.


1 Answers

The solution is to do the following, rather than only adding a block for only System.Management.Automation as suggested by the posts I read, you need to add one for all referenced PS assemblies.

  <runtime>       <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">         <dependentAssembly>             <assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />             <publisherPolicy apply="no" />           </dependentAssembly>         <dependentAssembly>           <assemblyIdentity name="Microsoft.PowerShell.Commands.Utility" publicKeyToken="31bf3856ad364e35" />           <publisherPolicy apply="no" />         </dependentAssembly>         <dependentAssembly>           <assemblyIdentity name="Microsoft.PowerShell.ConsoleHost" publicKeyToken="31bf3856ad364e35" />           <publisherPolicy apply="no" />         </dependentAssembly>         <dependentAssembly>           <assemblyIdentity name="Microsoft.PowerShell.Commands.Management" publicKeyToken="31bf3856ad364e35" />           <publisherPolicy apply="no" />         </dependentAssembly>         <dependentAssembly>           <assemblyIdentity name="Microsoft.PowerShell.Security" publicKeyToken="31bf3856ad364e35" />           <publisherPolicy apply="no" />         </dependentAssembly>         <dependentAssembly>           <assemblyIdentity name="Microsoft.PowerShell.Commands.Diagnostics" publicKeyToken="31bf3856ad364e35" />           <publisherPolicy apply="no" />         </dependentAssembly>         </assemblyBinding>     </runtime> 
like image 92
keyoke Avatar answered Sep 22 '22 18:09

keyoke