Get-PSReadlineKeyHandler and Set-PSReadlineKeyHandler throw TypeInitializer exceptions #6478

Open
opened 2026-01-31 00:39:53 +00:00 by claunia · 0 comments
Owner

Originally created by @Sarafian on GitHub (Feb 16, 2020).

Environment

Windows build number: Microsoft Windows [Version 10.0.19041.21]
Windows Terminal version (if applicable): 0.9.433.0

PowerShell Core: 6.2.4

Steps to reproduce

After updating the Windows Terminal from the store, my profile scripts started throwing TypeInitializer exceptions for Set-PSReadlineKeyHandler and Get-PSReadlineKeyHandler that are invoked as part of my pwsh profile.

The code that registers a KeyHandler is

    Set-PSReadlineKeyHandler -Chord "Ctrl+Alt+1" -BriefDescription 'Toggle $DebugPreference' -Description 'Toggle $DebugPreference between Continue and SilentlyContiinue' -ScriptBlock {
        if($DebugPreference -eq 'Continue')
        {
            Write-Debug "Setting DebugPreference=SilentlyContinue"
            Set-Variable -Name DebugPreference -Value "SilentlyContinue" -Scope Global -Force
            return
        }
        if($DebugPreference -eq 'SilentlyContinue')
        {
            Set-Variable -Name DebugPreference -Value "Continue" -Scope Global -Force
            Write-Debug "Setting DebugPreference=$DebugPreference"
            return
        }
    }

And before the profile script finishes and overview is produced like this

    Get-PSReadlineKeyHandler |Where-Object -Property Function -Like "Toggle*" | Format-Table Key,Description
    Get-PSReadlineKeyHandler |Where-Object -Property Function -Like "Reload*" | Format-Table Key,Description

Expected behavior

The expected behavior is for the keyhandlers to register and the profile to finish loading with this

Key        Description
---        -----------
Ctrl+Alt+1 Toggle $DebugPreference between Continue and SilentlyContiinue
Ctrl+Alt+3 Toggle $InformationPreference between Continue and SilentlyContiinue
Ctrl+Alt+2 Toggle $VerbosePreference between Continue and SilentlyContiinue


Key        Description
---        -----------
Ctrl+Alt+0 Reload profile

Actual behavior

TypeInitializer Exceptions for both cmdlets were thrown. Issue didn't resolve despite new sessions and restarting the terminal. But it somehow got fixed only after I started the powershell core and the profile loaded without problems. This happened on first execution. Then it also started working in the terminal. For this reason I don't have the exceptions. I cannot find if and where the transcriptions files of core are to find the errors. If you can help I can provide more information although from general experience they don't say anything useful.

During this short period of problems to resolution, the Windows Store was updating other apps. I don't use many so it was mostly default ones but I thought it could be of interest especially because of the nature of TypeInitializer exceptions.

I'm not saying there is something to actually fix here because I don't have the problem any longer and I can't really prove it. The bug submission is mostly to raise awareness and share if other do something similar.

Originally created by @Sarafian on GitHub (Feb 16, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: Microsoft Windows [Version 10.0.19041.21] Windows Terminal version (if applicable): 0.9.433.0 PowerShell Core: 6.2.4 ``` # Steps to reproduce After updating the Windows Terminal from the store, my profile scripts started throwing TypeInitializer exceptions for `Set-PSReadlineKeyHandler` and `Get-PSReadlineKeyHandler` that are invoked as part of my `pwsh` profile. The code that registers a KeyHandler is ```powershell Set-PSReadlineKeyHandler -Chord "Ctrl+Alt+1" -BriefDescription 'Toggle $DebugPreference' -Description 'Toggle $DebugPreference between Continue and SilentlyContiinue' -ScriptBlock { if($DebugPreference -eq 'Continue') { Write-Debug "Setting DebugPreference=SilentlyContinue" Set-Variable -Name DebugPreference -Value "SilentlyContinue" -Scope Global -Force return } if($DebugPreference -eq 'SilentlyContinue') { Set-Variable -Name DebugPreference -Value "Continue" -Scope Global -Force Write-Debug "Setting DebugPreference=$DebugPreference" return } } ``` And before the profile script finishes and overview is produced like this ```powershell Get-PSReadlineKeyHandler |Where-Object -Property Function -Like "Toggle*" | Format-Table Key,Description Get-PSReadlineKeyHandler |Where-Object -Property Function -Like "Reload*" | Format-Table Key,Description ``` # Expected behavior The expected behavior is for the keyhandlers to register and the profile to finish loading with this ```none Key Description --- ----------- Ctrl+Alt+1 Toggle $DebugPreference between Continue and SilentlyContiinue Ctrl+Alt+3 Toggle $InformationPreference between Continue and SilentlyContiinue Ctrl+Alt+2 Toggle $VerbosePreference between Continue and SilentlyContiinue Key Description --- ----------- Ctrl+Alt+0 Reload profile ``` # Actual behavior `TypeInitializer` Exceptions for both cmdlets were thrown. Issue didn't resolve despite new sessions and restarting the terminal. But it somehow got fixed only after I started the powershell core and the profile loaded without problems. This happened on first execution. Then it also started working in the terminal. For this reason I don't have the exceptions. I cannot find if and where the transcriptions files of core are to find the errors. If you can help I can provide more information although from general experience they don't say anything useful. During this short period of problems to resolution, the Windows Store was updating other apps. I don't use many so it was mostly default ones but I thought it could be of interest especially because of the nature of `TypeInitializer` exceptions. I'm not saying there is something to actually fix here because **I don't have the problem any longer** and I can't really prove it. The bug submission is mostly to raise awareness and share if other do something similar.
claunia added the Needs-Tag-FixResolution-No-Repro labels 2026-01-31 00:39:53 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#6478