Cyv*_*val 7 c# windows asp.net-mvc visual-studio
我正在使用ASP.NET MVC中的一个简单的记录管理Web应用程序.构建成功.但是,当我转到Package Manager Console时,我总是会收到此错误.
The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception.
有人可以向我解释这个错误吗?我总是得到它,它在发展中困扰我.提前致谢.
以下信息是从此 Visual Studio NuGet 控制台错误报告票证线程中收集的: https: //github.com/NuGet/Home/issues/1638
原因
根据Yishai Galatzer (Microsoft) 的评论,该问题是由属于 System.Management.Automation 3.0 一部分的 PowerShell DLL 中的堆栈溢出错误引起的。显然,带有该错误的更新 DLL 在过去几周的某个时间作为 Windows 更新的一部分进行了分发。
另外,根据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 更新上线,我将取消文件中的解决方法devenv.exe.config。
更新
该修复已在2016 年 1 月 12 日的 Windows 更新中发布,据 Yishai Galatzer (Microsoft) 报道。
| 归档时间: | 
 | 
| 查看次数: | 5605 次 | 
| 最近记录: |