PowerShell 3: Results of the execution of each command In "The type initializer [...] threw an exception" Error

Description

I installed a new version of PowerShell on my system a few months ago. Since then, something strange happens every time I use the shell. This does not interfere with functionality, but it bothers and challenges me because every time at the end of the command I should see a red error message.

(I am not a .NET expert, and I have never done anything unexpected for .NET or PowerShell.)

Shell output

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

What is the German version:

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

My question

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

(If you need more information about my PowerShell, write a command and specify what information you need.)

(I hope I understand what I want to ask. However, if this is not the case, write a comment that describes what is unclear!)


UPDATE:

(Shell / exit when 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 %> _ 

What is the German version:

 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 %> _ 
+4
source share
2 answers

The only code that runs inside the "type initializer" (i.e., the static constructor) is that it fills the array of sentences from resource strings. In my opinion, either the resource files were deleted, or damaged, or something strange in the language / culture settings of your system that do not allow you to work with a resource that depends on the culture. I suggest either reinstalling PowerShell 3.0, or checking that your operating system language matches the language of the PowerShell installer. Excuse me!

0
source

I seem to recall that I saw this (in a virtual machine!) Once during beta testing - for some reason, it was a duff installation. Can you reinstall?

This, of course, is NOT intended behavior.

Speaking in person, I find a complete reinstallation of ever 6-18 months, this is a good idea, because I play with a lot of beta programs. My laptop got a treatement reinstall this week and it works much better!

0
source

Source: https://habr.com/ru/post/1434442/


All Articles