Choco: Error when installing package: "Collection is read-only"

Created on 13 Mar 2016  路  34Comments  路  Source: chocolatey/choco

What You Are Seeing?

"Collection is read-only" error in newer (insider) Windows builds. This happens when installing any package.

capture

What is Expected?

Package installs and doesn't error.

How Did You Get This To Happen? (Steps to Reproduce)

  1. Install latest Windows Insider build.
  2. Install chocolatey
  3. Attempt to install any package

This has happened across multiple machines.

Output Log

https://gist.github.com/scowalt/5cfc70636850df7cb5f9

3 - Done Bug Priority_HIGH

Most helpful comment

This has been released in 0.9.9.12 and today's beta release for 0.9.10.

All 34 comments

Whoa... wtf Powershell?!

Turns out this doesn't repro with the latest Insider Preview build of Windows. I'll let you know if that changes.

@Tom999Hall this

Looks like the same - this is on the latest insider Preview - Win10 x64, Build 14291

@scowalt @Tom999Hall if you upgrade to the latest beta of 0.9.10, are you still seeing this error?

I got the same error trying to upgrade
chocolatey beta

@Tom999Hall I just thought of that yeah. You try to use https://chocolatey.org/installabsolutelatest.ps1 and run the installer to get the beta.

Installed/upgraded to 0.9.10 beta Ok, but still getting
ERROR: Collection is read-only. at , : line 1

Can you try isolating this for me?

Call:
& C:\ProgramData\chocolatey\helpers\chocolateyScriptRunner.ps1 - there should be an error, I just want to get an idea if the above error is related to something in this script or another reason.

Add the error log or an image back here after you run this

chocolateyscriptrunner

Contents of the file?

Two things. Contents of the file and can you tell me the specific encoding of the file? (Notepad++ can provide this information easily). I'm looking for UTF-8 with or without BOM.

Actually, line 1 - we specify parameters in a script.

I just looked and the file for me is UTF w/BOM. So is the chocolateyInstaller.psm1 file.

DO me a huge favor.

Create these two files:

TestWithParams.ps1:

param (
  [string]$TestVariable
)

$invocation = $MyInvocation
$argumentsPassed = $invocation.UnboundArguments -Join ' '
Write-Output "Received [$($invocation.InvocationName) $argumentsPassed]"

TestNoParams.ps1:

$invocation = $MyInvocation
$argumentsPassed = $invocation.UnboundArguments -Join ' '
Write-Output "Received [$($invocation.InvocationName) $argumentsPassed]"

Now run both as

  • & C:\TestWithParams -TestVariable 'Hi' -OtherArgument 'yep'
  • & C:\TestNoParams -TestVariable 'Hi' -OtherArgument 'yep'

This was my output:

Posh v2

PS C:\> & C:\code\temp\powershellparams\TestNoParams.ps1 -TestVariable 'Hi' -OtherArgument 'yep'
Received [& -TestVariable Hi -OtherArgument yep]
PS C:\> & C:\code\temp\powershellparams\TestWithParams.ps1 -TestVariable 'Hi' -OtherArgument 'yep'
Received [& -OtherArgument yep]
PS C:\> $host.version

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1

PowerShell v2 output

Posh v3

PS C:\> & C:\code\temp\powershellparams\TestNoParams.ps1 -TestVariable 'Hi' -OtherArgument 'yep'
Received [& -TestVariable Hi -OtherArgument yep]
PS C:\> & C:\code\temp\powershellparams\TestWithParams.ps1 -TestVariable 'Hi' -OtherArgument 'yep'
Received [& -OtherArgument yep]
PS C:\> $host.version

Major  Minor  Build  Revision
-----  -----  -----  --------
3      0      -1     -1

PowerShell v3 output

Posh v4

PS C:\> & C:\code\temp\powershellparams\TestNoParams.ps1 -TestVariable 'Hi' -OtherArgument 'yep'
Received [& -TestVariable Hi -OtherArgument yep]
PS C:\> & C:\code\temp\powershellparams\TestWithParams.ps1 -TestVariable 'Hi' -OtherArgument 'yep'
Received [& -OtherArgument yep]
PS C:\> $host.version

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1

PowerShell v4 output

Posh v 5.0.10240.16384 (the default version shipping in Windows 10)

PS C:\> & C:\code\temp\powershellparams\TestNoParams.ps1 -TestVariable 'Hi' -OtherArgument 'yep'
Received [& -TestVariable Hi -OtherArgument yep]
PS C:\> & C:\code\temp\powershellparams\TestWithParams.ps1 -TestVariable 'Hi' -OtherArgument 'yep'
Received [& -OtherArgument yep]
PS C:\> $host.version

Major  Minor   Build    Revision
-------   -------   -------    -----------
5         0         10240   16384

PowerShell v 5.0.10240.16384 output

Posh v 5.0.10514.6 (WMF 5 Final)

PowerShell v 5.0.10514.6 output

Here's mine ...
test powershell scripts

Well that validates it is not params. Okay, let's incrementally add parts of the chocolateyScriptRunner.ps1 into TestWithParams.ps1 one until we find the culprit. Can you do that for me?

Unfortunately, I鈥檝e got to go out for a couple of hours

No worries, it will be here when you get back.

https://github.com/chocolatey/choco/blob/0.9.9.11/src/chocolatey.resources/helpers/chocolateyScriptRunner.ps1 - If I had to guess, I'd believe it is $Warning that is causing the issue:

$RunNote = "DarkCyan"
$Warning = "Magenta"
$ErrorColor = "Red"
$Note = "Green"

@ferventcoder

Yes, bug in PowerShell in the latest insider build. Will get it fixed, in the meanwhile you can fix the issue on your side by changing (in file choco/src/chocolatey.resources/helpers/chocolateyScriptRunner.ps1)

From:
[alias("params")][alias("parameters")][alias("pkgParams")]

To:
[alias("params","parameters","pkgParams")]

Ah! Thanks @HemantMahawar!

This has been released in 0.9.9.12 and today's beta release for 0.9.10.

Thanks for addressing this so quickly @ferventcoder !

No worries. I didn't want to put out a 0.9.9.12 but this is a pretty gating issue for Choco, so I created the branch from the last tag and we'll have a short-lived 0.9.9.x branch.

As an aside, git is awesome. :+1:

(also, friendly reminder to update install.ps1 on the website :smile:)

Thanks, forgot that was changed to be hardcoded!

Done.

Quick note to anyone else pasting the fix from @HemantMahawar - the quotes are smart quotes (which is why your text search is failing). Thanks for the fix!

Fixed. Thanks for noting that @GeorgeHahn!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

morochena picture morochena  路  5Comments

ExE-Boss picture ExE-Boss  路  3Comments

jabrena picture jabrena  路  4Comments

michaelmhoffman picture michaelmhoffman  路  4Comments

dustojnikhummer picture dustojnikhummer  路  4Comments