【问题标题】:PowerShell 3: Every Command Execution Results In "The type initializer [...] threw an exception" ErrorPowerShell 3:每个命令执行都会导致“类型初始化程序 [...] 引发异常”错误
【发布时间】:2012-09-08 20:27:40
【问题描述】:

说明

几个月前,我在我的系统上安装了新的 PowerShell 版本。从那以后,每次我使用 shell 时都会发生一些奇怪的事情。它不会影响功能,但它让我感到困扰和困扰,因为每次在命令执行结束时我都必须看到红色错误消息。

(我不是 .NET 专家,我从未对 .NET 或 PowerShell 做过任何意想不到的事情。)

Shell 的输出

PS C:\\> my-cmdlet
Cmdlet-Ausgabe...   
Der Typeninitialisierer für "System.Management.Automation.HostUtilities" hat eine Ausnahme verursacht.
PS C:\\> _

这是德语版的:

PS C:\\> my-cmdlet
Cmdlet output...   
The type initializer for "System.Management.Automation.HostUtilities" threw an exception.
PS C:\\> _

我的问题

有没有办法停止这些错误消息(不会影响 PowerShell v3 的功能)? - 谢谢。

(如果您需要有关我的 PowerShell 的更多信息,请编写命令并描述您需要哪些信息。)

(我希望我想问的问题很清楚。但是,如果不是,请写一个评论来描述不清楚的地方!)


更新:

(Shellin-/运行时输出$error[0].exception.tostring()

PS %> my-cmdlet
Cmdlet-Ausgabe...
Der Typeninitialisierer für "System.Management.Automation.HostUtilities" hat eine Ausnahme verursacht.
PS %> $error[0].exception.tostring()
Es ist nicht möglich, eine Methode für einen Ausdruck aufzurufen, der den NULL hat.
In Zeile:1 Zeichen:1
+ $error[0].exception.tostring()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Der Typeninitialisierer für "System.Management.Automation.HostUtilities" hat eine Ausnahme verursacht.
PS %> _

那个德语版的:

PS %> my-cmdlet
Cmdlet-Output...
The type initializer for "System.Management.Automation.HostUtilities" threw an exception.
PS %> $error[0].exception.tostring()
You cannot call a method on a null-valued expression.
On line:1 char:1
+ $error[0].exception.tostring()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

The type initializer for "System.Management.Automation.HostUtilities" threw an exception.
PS %> _

【问题讨论】:

  • 请将$error[0].exception.tostring() 的输出添加到您的问题中。您应该在导致错误后直接运行它。
  • @x0n 我扩展了与此相关的问题文本。

标签: .net windows shell powershell powershell-3.0


【解决方案1】:

我似乎记得我在测试期间看到过这个(在虚拟机中!)一次 - 由于某种原因,它是一个 duff 安装。可以重新安装吗?

这当然不是预期的行为。

就我个人而言,我发现每 6 到 18 个月完全重新安装一次是个好主意,因为我确实玩过很多测试版软件。我的笔记本电脑本周早些时候接受了重新安装处理,并且运行得更好!

【讨论】:

    【解决方案2】:

    在“类型初始化程序”(即静态构造函数)内运行的唯一代码是从资源字符串填充一组建议的代码。在我看来,要么是资源文件已被删除或损坏,要么是系统的语言/文化设置有一些奇怪的地方阻止了特定于文化的资源检索工作。我建议重新安装 PowerShell 3.0 和/或验证操作系统的语言是否与 PowerShell 安装程序的语言相同。对不起!

    【讨论】:

    • 今天我不在我的 Windows 环境中工作。我稍后会尝试。 - 感谢您的回答。
    猜你喜欢
    • 2010-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 2013-05-15
    相关资源
    最近更新 更多