简体   繁体   中英

PowerShell 3: Every Command Execution Results In “The type initializer […] threw an exception” Error

Description

I've installed the new PowerShell version on my system a few months ago. Since that, something strange happens every time I use the shell. It doesn't trouble the functionality, but it's troubling and bugging me because every time at the end of a command execution I have to see the a red error message.

(I'm not a .NET expert and I never did something unanticipated to .NET or PowerShell.)

Output Of The Shell

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

That's the German version of:

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

My Question

Is there any way to stop these error messages (without troubling the functionality of PowerShell v3)? - Thanks.

(If you need more information about my PowerShell, please write a command and describe which information you need.)

(I hope it's clear what I wanted to ask. However, if it isn't, please write a comment describing what's unclear!)


UPDATE:

(Shellin-/output while running $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 %> _

That the German version of:

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 %> _

The only code that runs inside the "type initializer" (ie the static constructor) is something that populates an array of suggestions from resource strings. In my opinion, either the resource files have been deleted or corrupted, or there is something odd about your system's language/culture settings that prevent culture-specific resource retrieval from working. I suggest either reinstalling PowerShell 3.0 and/or verifying that the language of your operating system is the same as the language of the PowerShell installer. Sorry!

I seem to recall I saw this (in a VM!) once during the beta - it was a duff install for some reason. Can you do a re-install??

This is certainly NOT intended behavior.

Speaking personally, I find a complete re-install ever 6-18 months is a good idea as I do play with a lot of beta software. My laptop got the re-install treatement earlier this week and is running much better!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM