【问题标题】:The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception'System.Management.Automation.Runspaces.InitialSessionState' 的类型初始化程序引发异常
【发布时间】:2016-03-27 02:20:17
【问题描述】:

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

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

有人可以向我解释这个错误吗?我总是得到它,它在开发中困扰着我。提前致谢。

【问题讨论】:

  • 您可以尝试检查here 的建议,这可能是相关的。否则让Visual Studio创建一个ActivityLog,其中通常包含更多有关错误的技术信息,并在此处发布精华。
  • 我遇到了同样的问题,我重新启动了 Visual Studio,它就消失了。我正在使用 Visual Studio Community 2013。

标签: c# asp.net-mvc windows visual-studio


【解决方案1】:

以下信息是从此 Visual Studio NuGet 控制台错误报告票线程收集的:https://github.com/NuGet/Home/issues/1638

原因

根据 Yishai Galatzer (Microsoft) 的 this comment,该问题是由 System.Management.Automation 3.0 中的 PowerShell DLL 中的堆栈溢出错误引起的。带有错误的更新 DLL 显然是在过去几周的某个时候作为 Windows 更新的一部分分发的。

另外,根据 Yishai Galatzer 的 another comment,PowerShell 团队将在本月晚些时候(2016 年 1 月)发布针对此问题的修复程序。

解决方法/临时解决方案

“pete1208”posted 之前在同一线程中的以下解决方法:

在您的 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。

同样per Yishai Galatzer,此变通办法的效果是使用绑定重定向来强制加载 PowerShell 1.0。

我尝试了解决方法,它确实对我有用。我的 Visual Studio 2013 中的包管理器控制台再次正常运行。

我计划密切关注那个 NuGet 错误线程,一旦宣布带有 System.Management.Automation 修复的 Windows 更新已经上线,我将在我的 @ 中退出解决方法987654330@文件。

更新

根据 Yishai Galatzer(Microsoft)的说法,该修复程序已在 January 12, 2016 Windows Update 中发布。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 2013-05-15
    • 2013-11-08
    • 2019-07-08
    • 2013-10-06
    • 2015-08-31
    相关资源
    最近更新 更多