Skip to content

Get-PSReadLineOption : The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception. #614

Description

Environment data

& {
    "PS version: $($PSVersionTable.PSVersion)"
    "PSReadline version: $((Get-Module PSReadline).Version)"
    if ($IsLinux -or $IsOSX) {
        "os: $(uname -a)"
    } else {
        "os: $((dir $env:SystemRoot\System32\cmd.exe).VersionInfo.FileVersion)"
    }
    "PS file version: $((dir $pshome\pwsh.exe).VersionInfo.FileVersion)"
}
PS version: 6.0.0-rc.2
PSReadline version: 2.0.0
os: 6.1.7601.17514 (win7sp1_rtm.101119-1850)
PS file version: 6.0.0
$PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-rc.2
PSEdition                      Core
GitCommitId                    v6.0.0-rc.2
OS                             Microsoft Windows 6.1.7601 S
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.10032.0, 6.0.0-rc.2}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Steps to reproduce or exception report

Get-PSReadLineOption
Get-PSReadLineOption : The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception.
At line:1 char:1
+ Get-PSReadLineOption
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Get-PSReadLineOption], TypeInitializationException
+ FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.PowerShell.GetPSReadLineOption
Get-PSReadLineKeyHandler
Get-PSReadLineKeyHandler : The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception.
At line:1 char:1
+ Get-PSReadLineKeyHandler
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Get-PSReadLineKeyHandler], TypeInitializationException
+ FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.PowerShell.GetKeyHandlerCommand

note : the issue template dont reference 'pwsh.exe'

Activity

  1. lzybkr commented on Jan 16, 2018

    @lzybkr
    Contributor

    It looks like you built PSReadLine yourself - can you try with beta1 from the PSGallery?

    And if that doesn't repro, but it does repro with the latest, do let me know.

    I've done minimal testing on Win7 and haven't seen this. I have also done some testing with the "legacy" console on Win10 (from the console properties menu, on the Options tab, select "Use legacy console (requires relaunch)" - that option tends to help behavior specific to pre-Win10 systems.

  2. LaurentDardenne commented on Jan 16, 2018

    @LaurentDardenne
    Author

    can you try with beta1 from the PSGallery?
    This version comes from PSGallery, via Install-Module.
    I can test again on Win7 and on a new VM with Server 2016.

  3. lzybkr commented on Jan 16, 2018

    @lzybkr
    Contributor

    Thanks - I updated the issue template so the script now reports the prerelease version properly and also checks pwsh.exe.

  4. LaurentDardenne commented on Jan 17, 2018

    @LaurentDardenne
    Author

    Same error on Windows 7 (via Install-Module)

    Same error on Windows Server 2016 :
    New Azure VM : Windows Server 2016 Datacenter - with Containers

    Install PowerShell-6.0.0-win-x64.msi

    PS C:\Program Files\PowerShell\6.0.0> $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      6.0.0
    PSEdition                      Core
    GitCommitId                    v6.0.0
    OS                             Microsoft Windows 10.0.14393
    Platform                       Win32NT
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    
    PS C:\Program Files\PowerShell\6.0.0> get-module
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemPropert...
    Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
    Script     1.1.7.0    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Pack...
    Script     1.6.0      PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCap...
    Script     1.2        PSReadLine                          {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PS...
    
    
    PS C:\Program Files\PowerShell\6.0.0> install-module psreadline -verbose -force -SkipPublisherCheck  -AllowPrerelease
    ...
    VERBOSE: InstallPackageLocal' - name='PSReadLine', version='2.0.0-beta1',destination='C:\Users\Laurent\AppData\Local\Temp\2\1222363818'
    VERBOSE: Skipping the Publisher check for the version '2.0.0' of module 'PSReadLine'.
    VERBOSE: Module 'PSReadLine' was installed successfully to path 'C:\Program Files\PowerShell\Modules\PSReadLine\2.0.0'.
    
    #Close pwsh.exe
    #run pwsh.exe 
    PS C:\Program Files\PowerShell\6.0.0> get-module
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Script     2.0.0      PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PS...
    
    
    PS C:\Program Files\PowerShell\6.0.0> dir 'C:\Program Files\PowerShell\Modules\PSReadLine\2.0.0'
    
    
        Directory: C:\Program Files\PowerShell\Modules\PSReadLine\2.0.0
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    d-----        1/17/2018  11:27 AM                en-US
    -a----        12/5/2017  11:22 PM          14164 Changes.txt
    -a----        12/5/2017  11:22 PM           1322 License.txt
    -a----        12/5/2017  11:22 PM         249856 Microsoft.PowerShell.PSReadLine2.dll
    -a----        12/5/2017  11:22 PM           8770 PSReadLine.format.ps1xml
    -a----        12/5/2017  11:22 PM            869 PSReadLine.psd1
    -a----        12/5/2017  11:22 PM            180 PSReadLine.psm1
    -a----        12/5/2017  11:22 PM          21379 SamplePSReadLineProfile.ps1
    -a----        12/5/2017  11:22 PM          33256 System.Runtime.InteropServices.RuntimeInformation.dll
    
    PS C:\Program Files\PowerShell\6.0.0> Get-PSReadLineOption
    Get-PSReadLineOption : The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception.
    At line:1 char:1
    + Get-PSReadLineOption
    + ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-PSReadLineOption], TypeInitializationException
    + FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.PowerShell.GetPSReadLineOption
  5. tobiasdiez commented on Sep 5, 2018

    @tobiasdiez

    I've the same issue after a upgrade of Windows 10 (insider preview). I'm not aware that I've installed PSReadLine so I think that it comes bundled with Win 10 (in fact, I cannot remove it via Remove/Uninstall-Module)

     Name                           Value
    ----                           -----
    PSVersion                      6.1.0-rc.1
    PSEdition                      Core
    GitCommitId                    6.1.0-rc.1
    OS                             Microsoft Windows 10.0.17744
    Platform                       Win32NT
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    

    PSReadLine version: 2.0.0

  6. KurtDeGreeff commented on Sep 17, 2018

    @KurtDeGreeff

    I have the same issue here on Windows 7 with latest Powershell 6.1 installed :

  7. KurtDeGreeff commented on Sep 17, 2018

    @KurtDeGreeff

    Get-PSReadLineOption : The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception.
    At line:1 char:1

    • Get-PSReadLineOption
    • CategoryInfo : NotSpecified: (:) [Get-PSReadLineOption], TypeInitializationException
    • FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.PowerShell.GetPSReadLineOption
  8. RobertSpir commented on Sep 24, 2018

    @RobertSpir

    Same thing happens in latest win10 1809 insider build (build 17763.1) which will likely be the RTM build, any of the PSReadline commands throws an exception making it entirely useless

    PS version: 5.1.17763.1
    PSReadline version: 2.0.0-beta2
    os: 10.0.17763.1 (WinBuild.160101.0800)
    PS file version: 10.0.17763.1 (WinBuild.160101.0800)

    Get-PSReadLineOption : The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception.
    At line:1 char:1
    + Get-PSReadLineOption
    + ~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-PSReadLineOption], TypeInitializationException
        + FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.PowerShell.GetPSReadLineOption
    
  9. lzybkr commented on Sep 24, 2018

    @lzybkr
    Contributor

    RobertSpir - I'll need some help tracking this down, I'm always using the latest and never hit this problem.

    A memory dump or time trace debug trace would be very helpful if you don't have time to investigate yourself.

  10. RobertSpir commented on Sep 25, 2018

    @RobertSpir
    Set-PSDebug -Trace 2; Get-PSReadLineOption
    DEBUG:    1+ Set-PSDebug -Trace 2;  >>>> Get-PSReadLineOption
    DEBUG:   19+                                         if ( &  >>>> { Set-StrictMode -Version 1; $_.PSMessageDetails } )
    {
    DEBUG:     ! CALL function '<ScriptBlock>'
    DEBUG:   19+                                         if ( & {  >>>> Set-StrictMode -Version 1; $_.PSMessageDetails } )
    {
    DEBUG:   19+                                         if ( & { Set-StrictMode -Version 1;  >>>> $_.PSMessageDetails } )
    {
    DEBUG:    1+ &  >>>> { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails }
    DEBUG:     ! CALL function '<ScriptBlock>'
    DEBUG:    1+ & {  >>>> Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails }
    DEBUG:    1+ & { Set-StrictMode -Version 1;  >>>> $this.Exception.InnerException.PSMessageDetails }
    DEBUG:    1+ & { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails  >>>> }
    DEBUG:   19+                                         if ( & { Set-StrictMode -Version 1; $_.PSMessageDetails  >>>> } )
    {
    DEBUG:   26+                                         $errorCategoryMsg = &  >>>> { Set-StrictMode -Version 1;
    $_.ErrorCategory_Message }
    DEBUG:     ! CALL function '<ScriptBlock>'
    DEBUG:   26+                                         $errorCategoryMsg = & {  >>>> Set-StrictMode -Version 1;
    $_.ErrorCategory_Message }
    DEBUG:   26+                                         $errorCategoryMsg = & { Set-StrictMode -Version 1;  >>>>
    $_.ErrorCategory_Message }
    DEBUG:   26+                                         $errorCategoryMsg = & { Set-StrictMode -Version 1;
    $_.ErrorCategory_Message  >>>> }
    DEBUG:   42+                                         $originInfo = &  >>>> { Set-StrictMode -Version 1; $_.OriginInfo
    }
    DEBUG:     ! CALL function '<ScriptBlock>'
    DEBUG:   42+                                         $originInfo = & {  >>>> Set-StrictMode -Version 1; $_.OriginInfo
    }
    DEBUG:   42+                                         $originInfo = & { Set-StrictMode -Version 1;  >>>> $_.OriginInfo
    }
    DEBUG:   42+                                         $originInfo = & { Set-StrictMode -Version 1; $_.OriginInfo  >>>>
    }
    Get-PSReadLineOption : The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception.
    At line:1 char:23
    + Set-PSDebug -Trace 2; Get-PSReadLineOption
    +                       ~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-PSReadLineOption], TypeInitializationException
        + FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.PowerShell.GetPSReadLineOption
    

    this happens on all three machines that are upgraded to 17763

  11. RobertSpir commented on Sep 25, 2018

    @RobertSpir

    downgrading to 1.2 fixed this issue

  12. lzybkr commented on Sep 25, 2018

    @lzybkr
    Contributor

    Unfortunately the PowerShell debug trace isn't useful because PSReadLine is written in C#.

    Ideally I could get a TTD trace, but I could probably also debug from a memory dump.

    Note that if you can provide either - they both could contain secrets, e.g. all of your environment variables. Also note that either method will produce very large files, probably too large to email. If you can collect either the .run file form TTD or the .dmp file from .dump, then I can set up a secure location to share the file - you can email me or PM on twitter, whatever works for you.

  13. lzybkr commented on Sep 26, 2018

    @lzybkr
    Contributor

    RobertSpir provided a TTD trace and I think I understand the issue now.

    Can folks hitting this report back what keyboard layout or language you use?

  14. copdips commented on Sep 26, 2018

    @copdips

    Jason Shirk (@lzybkr),

    Thx for your tips, when I'm on french layout, I have the issue. I switch the keyboard layout to english, no more issue.

  15. tobiasdiez commented on Sep 26, 2018

    @tobiasdiez

    The keyboard layout seems to be the issue, indeed. When using NEO 2.0 (special German layout) I experience the problem but switching to the ordinary built-in German layout fixes it (until switching back). Thanks for having a look at this!

  16. 2 remaining items

  17. lzybkr commented on Sep 26, 2018

    @lzybkr
    Contributor

    Thanks.

    You can trying switching back to your preferred layout after PSReadLine is initialized, but there are known issues with switching after the process has started. One of those issues might be fixable withing PSReadLine, but there Staffan Gustafsson (@powercode) found that a Win32 api used by PSReadLine also does not work correctly when switching layouts.

    So for the time being, installing 1.2 might be the best workaround.

  18. SteveL-MSFT commented on Sep 27, 2018

    @SteveL-MSFT
    Member

    The problem seems to be that for some Windows keyboard layouts, the key modifiers are not considered distinct so that when the code here tries to add a new key into the dictionary, it already exists which throws an exception. My proposal for now is to not add keys that already exist. This doesn't fix the fundamental issue that some key bindings won't work for some keyboard layouts, but they wouldn't work currently anyways. The temporary fix will resolve the unhandled exception so that errors aren't being generated and Get-PSReadLineOption works for different keyboard layouts beyond En-US.

  19. RobertSpir commented on Sep 27, 2018

    @RobertSpir

    Confirming that with this fix applied everything works with slovak keyboard layout

  20. added a commit that references this issue on Sep 28, 2018
    e1c5b51
  21. eliohann commented on Oct 28, 2018

    @eliohann
          Confirming that with this fix applied everything works with slovak keyboard layout
    

    Can you explain how to Apply fix ? can find how to do it …

  22. SteveL-MSFT commented on Oct 28, 2018

    @SteveL-MSFT
    Member

    Vincent (@eliohann) you would need a new build of PSReadLine. There isn't a new beta coming soon, but you can pick up the nightly build which has the fix: https://ci.appveyor.com/project/lzybkr/PSReadLine/branch/master/artifacts

  23. Nicolas01 commented on Nov 12, 2018

    @Nicolas01

    Vincent (@eliohann) I installed the nightly build by replacing files in C:\Program Files\WindowsPowerShell\Modules\PSReadline\2.0.0
    And now it works with my custom keyboard layout !

  24. Kralizek commented on Jan 7, 2019

    @Kralizek

    Is there a better solution now? I tried to use the artifact from the AppVeyor build but I get

    Cannot load PSReadline module. Console is running without PSReadline.

  25. lzybkr commented on Jan 7, 2019

    @lzybkr
    Contributor

    You could try this build from this PR.

    It's not tested on Linux/Mac yet and I expect I've broken some things there, but I think it fixes all the issues on Windows.

  26. LaurentDardenne commented on Jan 12, 2019

    @LaurentDardenne
    Author

    I have the same error with a new install of Windows 10 Fr (1809).

    Installing the specified build no longer causes the exception, but some key combinations no longer work, for example ctrl-space.

    # Microsoft Windows [version 10.0.17763.253]
    $psversiontable
    
    Name                           Value
    ----                           -----
    PSVersion                      5.1.17763.134
    PSEdition                      Desktop
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17763.134}
    BuildVersion                   10.0.17763.134
    CLRVersion                     4.0.30319.42000
    WSManStackVersion              3.0
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
  27. SteveL-MSFT commented on Jan 15, 2019

    @SteveL-MSFT
    Member

    Laurent Dardenne (@LaurentDardenne) that is a known issue and being addressed by #831

  28. Kralizek commented on Jan 15, 2019

    @Kralizek

    Strangely enough, I was able to get the previous version to work by simply renaming the 2.0.0 folder so that it doesn't respect the pattern.

    I might be very well be exposed to some error but so far I haven't experienced anything strange.

  29. silverqx commented on Mar 6, 2019

    @silverqx

    RobertSpir How did you downgrade to 1.2? I don't know how to downgrade, I created #860 question when I describe what I tried

  30. silverqx commented on Mar 6, 2019

    @silverqx

    Ok, resolved at #860 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions