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

Prefs files get corrupted if used from both PowerShell and Windows PowerShell #148

Open
clairernovotny opened this issue Nov 26, 2024 · 0 comments

Comments

@clairernovotny
Copy link

clairernovotny commented Nov 26, 2024

Expected Behavior

The prefs.xml file should not be corrupt.

Current Behavior

See https://stackoverflow.com/a/40098904/738188 for details. The issue is that the default encoding for Export-Clixml is different on Windows PowerShell and PowerShell Core. In the former it's UTF16LE/BE and in PowerShell Core it's UTF8 w/o a BOM.

The default encodings are documented if you look at the PS-version specific doc page:

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/export-clixml?view=powershell-7.4#-encoding shows utf8NoBOM as the default while https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/export-clixml?view=powershell-5.1#-encoding shows Unicode as the default.

With many programs using PS and PS Core at the same time (in process consoles in VS Code, etc), it's highly likely that they'll step on each other.

Possible Solution

The solution should be to specify the -Encoding parameter on all uses of Export-Clixml and other commands that write files. That will prevent conflicting defaults.

Steps to Reproduce (for bugs)

prefs.xml.zip

Context

Frequent errors when launching a new terminal session from not being able to parse the prefs.

Your Environment

  • Module version used:
  • Operating System and PowerShell version:
    PS Core 7.4.6 and Windows PowerShell on Windows 11.
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

1 participant