c# - 'System.Management.Automation.Runspaces.InitialSessionState' 的类型初始值设定项抛出异常

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

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

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

有人可以向我解释这个错误吗?我一直都明白它,它困扰着我的发展。提前致谢。

最佳答案

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

原因

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

同样根据 another comment由 Yishai Galatzer 撰写,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,此解决方法的效果是使用绑定(bind)重定向强制加载 PowerShell 1.0。

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

我计划密切关注该 NuGet 错误线程,一旦宣布带有 System.Management.Automation 修复程序的 Windows 更新已上线,我将取消我的解决方法 devenv.exe.config 文件。

更新

此修复已在 January 12, 2016 Windows Update 中发布, 根据 Yishai Galatzer (Microsoft)。

关于c# - 'System.Management.Automation.Runspaces.InitialSessionState' 的类型初始值设定项抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34388394/

相关文章:

c# - 如何检测触发器中的对象?

c# - Azure 应用服务限制 - 允许应用服务 A 用于应用服务 B

c# - EntityFramework 6 连接已关闭

asp.net-mvc - 使用 "tel:"标签时,出现 "A potentially dangerous Request.Path value was detected from the client (:). "错误

c# - 在 asp.net mvc Twitter OAuth2 登录后获取 oauth 凭据

c# - 从字典中的列表中获取第一个元素 C#

c# - MemberExpression 在不应该返回 null 的情况下强制返回 null

c++ - QtWebKit C++ 连接 : cannot convert QWebView to SOCKET

Windows批处理脚本查找空闲文件名

windows - 我如何定位 Windows 98?