Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import-Clixml Error when opening Terminal #126

Open
Irtiza90 opened this issue Jan 31, 2024 · 3 comments
Open

Import-Clixml Error when opening Terminal #126

Irtiza90 opened this issue Jan 31, 2024 · 3 comments

Comments

@Irtiza90
Copy link

Irtiza90 commented Jan 31, 2024

Current Behavior

I get an error randomly when i open the terminal, it only gives an error at launch.

Error Message:

(yesterday, when i checked i received this error message)

Import-Clixml: Key for dictionary entry is not specified. Line 104, position 7.
InvalidOperation: Index operation failed; the array index evaluated to null.
Import-Clixml: 'Element' is an invalid XmlNodeType.
InvalidOperation: Index operation failed; the array index evaluated to null.
InvalidOperation: Index operation failed; the array index evaluated to null.

(this error i just received)

Import-Clixml: Value for dictionary entry is not specified. Line 109, position 21.
InvalidOperation: Index operation failed; the array index evaluated to null.
InvalidOperation: Index operation failed; the array index evaluated to null.
InvalidOperation: Cannot index into a null array.
InvalidOperation: Cannot index into a null array.
InvalidOperation: You cannot call a method on a null-valued expression.
InvalidOperation: You cannot call a method on a null-valued expression.

Steps to Reproduce (for bugs)

Opening the terminal randomly gives the error, sometimes i see the error, othertimes i don't.

The error doesn't seem to be causing any issues with the terminal, most probably just a visual error.

Your Environment

OS Version: Windows 10(22H2)
Terminal: Powershell 7.4.1
I'm using ohmyposh and Terminal-Icons powershell modules

@mattcargile
Copy link

mattcargile commented Jun 26, 2024

We would want to see the output from the below after the error.

get-error -last 2

Additionally, does the same error happen when you load PowerShell Core with no profile? You launch with pwsh -noprofile.

Lastly, it is possibly related to #121.

@hero3616
Copy link

hero3616 commented Sep 6, 2024

If you don't mind 1 second delay below profile works for me with a 2x2 split terminal startup with pwsh 7.4.5

oh-my-posh init pwsh --config '<your-config>.json' | Invoke-Expression

$WarningPreference = 'SilentlyContinue'
$ErrorActionPreference = 'SilentlyContinue'

Import-Module -Name Terminal-Icons

# set back to default values with a 1 second delay
Start-Sleep -Seconds 1
$WarningPreference = 'Continue'
$ErrorActionPreference = 'Continue'

@techthoughts2
Copy link

Similar error for me:

import-module terminal-icons
Import-Clixml: Value for dictionary entry is not specified. Line 603, position 40.

Full error:

PSMessageDetails      :
Exception             : System.Xml.XmlException: Value for dictionary entry is not specified. Line 603, position 40.
                           at System.Management.Automation.InternalDeserializer.ReadDictionary(ContainerType ct, ConsolidatedString
                        InternalTypeNames)
                           at System.Management.Automation.InternalDeserializer.ReadPSObject()
                           at System.Management.Automation.InternalDeserializer.ReadOneDeserializedObject(String& streamName, Boolean&
                        isKnownPrimitiveType)
                           at System.Management.Automation.InternalDeserializer.ReadOneObject(String& streamName)
                           at System.Management.Automation.InternalDeserializer.ReadDictionary(ContainerType ct, ConsolidatedString
                        InternalTypeNames)
                           at System.Management.Automation.InternalDeserializer.ReadPSObject()
                           at System.Management.Automation.InternalDeserializer.ReadOneDeserializedObject(String& streamName, Boolean&
                        isKnownPrimitiveType)
                           at System.Management.Automation.InternalDeserializer.ReadOneObject(String& streamName)
                           at System.Management.Automation.InternalDeserializer.ReadDictionary(ContainerType ct, ConsolidatedString
                        InternalTypeNames)
                           at System.Management.Automation.InternalDeserializer.ReadPSObject()
                           at System.Management.Automation.InternalDeserializer.ReadOneDeserializedObject(String& streamName, Boolean&
                        isKnownPrimitiveType)
                           at System.Management.Automation.InternalDeserializer.ReadOneObject(String& streamName)
                           at System.Management.Automation.Deserializer.Deserialize(String& streamName)
                           at System.Management.Automation.Deserializer.Deserialize()
                           at Microsoft.PowerShell.Commands.ImportXmlHelper.Import()
                           at Microsoft.PowerShell.Commands.ImportClixmlCommand.ProcessRecord()
                           at System.Management.Automation.CommandProcessor.ProcessRecord()
TargetObject          :
CategoryInfo          : NotSpecified: (:) [Import-Clixml], XmlException
FullyQualifiedErrorId : System.Xml.XmlException,Microsoft.PowerShell.Commands.ImportClixmlCommand
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, C:\Users\jakew\OneDrive\Documents\PowerShell\Modules\terminal-icons\0.11.0\Terminal-Icons.psm1: line
                        3419
                        at <ScriptBlock>, C:\Users\jakew\OneDrive\Documents\PowerShell\Modules\terminal-icons\0.11.0\Terminal-Icons.psm1: line
                        3418
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

When exploring these lines in Terminal-Icons.psm1:

(Get-ChildItem $userThemePath -Filter '*_icon.xml').ForEach({
    $userIconTheme = Import-CliXml -Path $_.FullName
    $userThemeData.Themes.Icon[$userIconTheme.Name] = $userIconTheme
})

I found that $userIconTheme tracked back to $basePath = [Environment]::GetFolderPath('ApplicationData').

This location did not contain the expected xml files, thus why this error was occuring.

My workaround to address this for me was:

  1. Launch cmd.exe
  2. Run pwsh -noprofile
  3. Run Import-Module terminal-icons

The above steps caused the module to create a: AppData\Roaming\powershell\Community\Terminal-Icons and the module is now able to be imported in Terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants