Recently I came across the error The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception, when I am trying to open the Package Manager Console.
As per comment form Yishai Galatzer this is caused by a stack overflow bug in a PowerShell DLL
Workaround
In your Visual Studio folder, make a backup copy of file devenv.exe.config
.
Then, in the original devenv.exe.config file, insert the following after the opening assemblyBinding
element(run as admin) and save the file
<!-- WORKAROUND START ->
<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>
<!-- WORKAROUND END -->
To Make the changes effect you'll need to restart VS.
Cheers,
Samitha