23

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?

Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47
keyoke
  • 1,209
  • 12
  • 26

5 Answers5

37

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>
keyoke
  • 1,209
  • 12
  • 26
  • Perfect -- this was the missing additional information from this post on the same topic: http://stackoverflow.com/questions/12060460/using-powershell-2-as-default-version-on-windows-8/ – CJBS Feb 05 '14 at 23:02
  • 7
    With Visual Studio 2013 on Windows 8.1, adding these lines to the `` section of `%APPDATA%\..\Local\Microsoft\VisualStudio\12.0\devenv.exe.config` solves the problem. – Aidan Fitzpatrick May 28 '14 at 13:49
  • 12
    It failed for me in VS2015, and this advice has been helpful for it. Just open `c:\Users\%username%\AppData\Local\Microsoft\VisualStudio\14.0\devenv.exe.config` and add the same lines. – ForNeVeR Oct 09 '15 at 17:37
  • 3
    Unfortunately, from time to time Visual Studio regenerates this file and the change is lost, so you have to put it back. – Matthew Walton Nov 02 '15 at 11:17
  • 1
    almost 4 years later and this is still the only solution? – AndrewK Jul 13 '16 at 18:46
  • Added %APPDATA%\..\Local\Microsoft\VisualStudio\15.0_311b6a3\devenv.exe.co‌​nfig I have a 15.0 folder and a 15.0_311b6a3 (????) folder. Working!!! Thank you for the post. – Carl Clark Jan 04 '18 at 01:56
  • 18-Feb-2018 - The above "solution" has no effect when running on Windows 10 using VS 15.5.6 -- Basically, I am unable to use NuGet with Visual studio, see: https://stackoverflow.com/questions/48837473/visual-studio-2017-unable-to-initialize-powershell-host-day-1-and-2 – bdcoder Feb 18 '18 at 14:59
7

I had the same problem in VS 2015 Update 3.

I must remove the folder:

%APPDATA%\Local\Microsoft\VisualStudio\

and then add into:

c:\Users\%username%\AppData\Local\Microsoft\VisualStudio\14.‌​0\devenv.exe.config

in section:

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

the following lines:

<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>

I lost two days searching for solutions... thanks MS :-/

Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47
Pavel Riedl
  • 71
  • 1
  • 3
1

above answer did not work for me, i fixed the problem by removing the %APPDATA%..\Local\Microsoft\VisualStudio\ folder.

Upon restarting VS this folder is recreated and the package manager console works again. A little crude but it does the job.

1

After trying the solution in the accepted answer and getting tired of Visual Studio resetting the file, I reinstalled VS 2015 from scratch and haven't had the problem since. If you find the issue persists, the nuclear option is definitely worth a try.

SamStrong
  • 66
  • 2
0

Install the appropriate version of PowerShell for your OS:

  • Windows XP SP2 / Vista / 2003 / 2008 - PowerShell v1.0
  • Windows XP SP3 / Vista SP1 / 7 / 2003 SP2 / 2008 R2 - PowerShell v2.0
  • Windows 7 SP1 / 8 / 2008 SP1 / 2008 R2 SP1 / 2012 - PowerShell v3.0
  • Windows 7 SP1 / 8.1 / 2008 R2 SP1 / 2012 / 2012 R2 - PowerShell v4.0
  • Windows 7 SP1 / 8.1 / 2008 R2 SP1 / 2012 / 2012 R2 - PowerShell v5.0 (as part of Windows Management Framework (WMF) 5.0)
Bob Kiefer
  • 13
  • 3
  • Windows XP SP2 / Vista / 2003 / 2008 - PowerShell v1.0 Windows XP SP3 / Vista SP1 / 7 / 2003 SP2 / 2008 R2 - PowerShell v2.0 Windows 7 SP1 / 8 / 2008 SP1 / 2008 R2 SP1 / 2012 - PowerShell v3.0 Windows 7 SP1 / 8.1 / 2008 R2 SP1 / 2012 / 2012 R2 - PowerShell v4.0 Windows 7 SP1 / 8.1 / 2008 R2 SP1 / 2012 / 2012 R2 - PowerShell v5.0 (as part of Windows Management Framework (WMF) 5.0) – Bob Kiefer Jul 28 '16 at 21:14
  • To install in the native OS releases, go to: -Control Panel\All Control Panel Items\Programs and Features or the equivalent, -then click on the 'Turn Windows features on or off' link, -click on 'Features' in the MMC tree view in the left-side navigation pane, -then click the 'Add Features' link on the right side of the 'Features Summary' pane accordion child section -Finally, check the checkbox for Windows PowerShell Integrated Scripting Environment (ISE) or equivalent (name may differ in different OSes) – Bob Kiefer Jul 28 '16 at 21:30
  • See the original release versions and matching OSes here, in the 'Versions' section: – Bob Kiefer Jul 28 '16 at 21:30