'System.Management.Automation.Runspaces.InitialSessionState'的类型初始值设定项引发了异常 [英] The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception

查看:252
本文介绍了'System.Management.Automation.Runspaces.InitialSessionState'的类型初始值设定项引发了异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASP.NET MVC开发一个简单的记录管理Web应用程序.构建成功.但是,当我进入Package Manager控制台时,总是会收到此错误.

The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception.

有人可以向我解释这个错误吗?我一直都得到它,这在开发中困扰着我.预先感谢.

解决方案

以下信息是从此Visual Studio NuGet Console错误报告票证线程中收集的:此评论,问题是由于PowerShell中的堆栈溢出错误引起的DLL是System.Management.Automation 3.0的一部分.带有错误的经过更新的DLL显然是在过去几周的某个时间作为Windows Update的一部分分发的.

此外,根据Yishai Galatzer的另一条评论,PowerShell小组将即将发布修复程序,希望在本月晚些时候(2016年1月)发布.

解决方法/临时解决方案

"pete1208" 发布先前在同一线程中的以下变通方法:

在Visual Studio文件夹中,制作文件devenv.exe.config的备份副本.

然后,在原始devenv.exe.config文件中,在打开的assemblyBinding元素之后插入以下内容:

<!-- WORKAROUND START for NuGet Console error: 
  "The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception" 
  Author: pete1208 from https://github.com/NuGet/Home/issues/1638 -->
<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 -->

(您可能需要管理员最喜欢的文本编辑器的管理员提升版本,才能将文件保存到Visual Studio文件夹中.)

然后,重新启动Visual Studio.

再次 Yishai Galatzer,此解决方法的作用是使用绑定重定向来强制加载PowerShell 1.0.

我尝试了变通方法,它确实为我工作. Visual Studio 2013中的程序包管理器控制台"再次正常工作.

我打算密切关注该NuGet错误线程,一旦发布有关System.Management.Automation修复程序的Windows Update正式发布,我将在devenv.exe.config文件.

更新

此修复程序已在 2016年1月12日Windows Update 中发布, Yishai Galatzer(微软).

I was working on a simple record management web app in ASP.NET MVC. The build was successful. However, when I go to Package Manager Console, I always get this error.

The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception.

Can somebody please explain this error to me? I get it all the time and it bothers me in development. Thanks in advance.

解决方案

The following information was gathered from this Visual Studio NuGet Console bug report ticket thread: https://github.com/NuGet/Home/issues/1638

Cause

Per this comment from Yishai Galatzer (Microsoft), the problem is caused by a stack overflow bug in a PowerShell DLL that's part of System.Management.Automation 3.0. The updated DLL with the bug evidently was distributed as part of Windows Updates sometime in the past few weeks.

Also per another comment by Yishai Galatzer, the PowerShell team will be releasing a fix for this, hopefully later this month (January 2016).

Workaround / Temporary Solution

"pete1208" posted the following workaround earlier in that same thread:

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 just after the opening assemblyBinding element:

<!-- WORKAROUND START for NuGet Console error: 
  "The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception" 
  Author: pete1208 from https://github.com/NuGet/Home/issues/1638 -->
<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 -->

(You'll probably need an admin-elevated version of your favorite text editor to save the file to your Visual Studio folder.)

Then, restart Visual Studio.

Again per Yishai Galatzer, the effect of this workaround is to use binding redirects to force loading PowerShell 1.0.

I tried the workaround, and it did work for me. My Package Manager Console in my Visual Studio 2013 is once again functional.

I'm planning to keep an eye on that NuGet bug thread, and once the announcement is made that the Windows Update with the System.Management.Automation fix is live, I'm going to back out the workaround in my devenv.exe.config file.

Update

The fix was released in the January 12, 2016 Windows Update, per Yishai Galatzer (Microsoft).

这篇关于'System.Management.Automation.Runspaces.InitialSessionState'的类型初始值设定项引发了异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆