Title: Array subexpression @($list) throws "Argument types do not match" for List[object] created by New-Object · Issue #27558 · PowerShell/PowerShell · GitHub
Open Graph Title: Array subexpression @($list) throws "Argument types do not match" for List[object] created by New-Object · Issue #27558 · PowerShell/PowerShell
X Title: Array subexpression @($list) throws "Argument types do not match" for List[object] created by New-Object · Issue #27558 · PowerShell/PowerShell
Description: Summary The array-subexpression operator itself throws System.ArgumentException: Argument types do not match when it wraps a System.Collections.Generic.List[object] created by New-Object. UI Automation, ConvertTo-Json, and the original $...
Open Graph Description: Summary The array-subexpression operator itself throws System.ArgumentException: Argument types do not match when it wraps a System.Collections.Generic.List[object] created by New-Object. UI Automa...
X Description: Summary The array-subexpression operator itself throws System.ArgumentException: Argument types do not match when it wraps a System.Collections.Generic.List[object] created by New-Object. UI Automa...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/27558
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Array subexpression @($list) throws \"Argument types do not match\" for List[object] created by New-Object","articleBody":"## Summary\n\nThe array-subexpression operator itself throws `System.ArgumentException: Argument types do not match` when it wraps a `System.Collections.Generic.List[object]` created by `New-Object`.\n\nUI Automation, `ConvertTo-Json`, and the original `$pair[1]` access are not required. They only made the issue visible in the original application.\n\n## Minimal reproduction\n\n```powershell\n$list = New-Object System.Collections.Generic.List[object]\n@($list)\n```\n\nThe list can be empty.\n\n### Actual output\n\n```text\nOperationStopped: Argument types do not match\n```\n\n### Expected output\n\n`@($list)` should not throw and should behave consistently with the same public .NET type created with its constructor. In the tested environment, the constructor-created empty list produces an empty `object[]`:\n\n```powershell\n$list = [System.Collections.Generic.List[object]]::new()\n@($list) # succeeds\n```\n\n## Comparison\n\n```powershell\nfunction Test-Case($name, [scriptblock]$body) {\n try {\n \u0026 $body | Out-Null\n $name + ': OK'\n }\n catch {\n $name + ': FAIL - ' + $_.Exception.Message\n }\n}\n\n$newObjectList = New-Object System.Collections.Generic.List[object]\n$constructorList = [System.Collections.Generic.List[object]]::new()\n\nTest-Case 'New-Object + @()' { @($newObjectList) }\nTest-Case 'constructor + @()' { @($constructorList) }\nTest-Case 'New-Object + [array]' { [array]$newObjectList }\nTest-Case 'New-Object + ToArray' { $newObjectList.ToArray() }\n```\n\nObserved:\n\n```text\nNew-Object + @(): FAIL - Argument types do not match\nconstructor + @(): OK\nNew-Object + [array]: OK\nNew-Object + ToArray: OK\n```\n\nBoth values report the same public types:\n\n```text\nGetType(): System.Collections.Generic.List[System.Object]\nPSObject.BaseObject type: System.Collections.Generic.List[System.Object]\nPSObject.ImmediateBaseObject type: System.Collections.Generic.List[System.Object]\n```\n\nThe failure is specific in the tested matrix:\n\n| Construction/type | `@(...)` |\n|---|---|\n| `New-Object List[object]` | FAIL |\n| `[List[object]]::new()` | OK |\n| `New-Object List[string]` | OK |\n| `New-Object List[int]` | OK |\n| `New-Object ArrayList` | OK |\n| `New-Object Queue[object]` | OK |\n\n## Stack trace\n\nThe exception occurs while evaluating `@($list)`, before any JSON serialization. The top stack frames are:\n\n```text\nat System.Linq.Expressions.Expression.Condition(...)\nat System.Management.Automation.Language.PSEnumerableBinder.MaybeDebase(...)\nat System.Management.Automation.Language.PSToObjectArrayBinder.Bind(...)\n```\n\n## Workarounds\n\n```powershell\n$list = [System.Collections.Generic.List[object]]::new()\n[array]$list\n$list.ToArray()\n```\n\nIn the original application, removing the unnecessary array-subexpression also avoids the failure:\n\n```diff\n- controls = @($pair[1])\n+ controls = $pair[1]\n```\n\n## Environment\n\nReproduced on:\n\n- PowerShell 7.6.3 on Windows 11 10.0.26200\n- Windows PowerShell 5.1.26100.8655 on the same machine\n\nThe original report attributed the failure to UI Automation-derived hashtables and `ConvertTo-Json`. Further reduction after reviewer feedback shows that neither is required.\n\n## Related issues\n\n- [PowerShell #5579](https://github.com/PowerShell/PowerShell/issues/5579): implicit `PSObject` wrapping and serialization behavior\n- [PowerShell #4280](https://github.com/PowerShell/PowerShell/issues/4280) and [PR #4296](https://github.com/PowerShell/PowerShell/pull/4296): earlier work on array-subexpression behavior and `List[object]`\n","author":{"url":"https://github.com/shuangxue520","@type":"Person","name":"shuangxue520"},"datePublished":"2026-06-03T15:07:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/27558/PowerShell/issues/27558"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1320126f-bf74-ea59-11f0-07e1713e6061 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BE88:3D1150:3E0BB9:51DDFD:6A5B26B8 |
| html-safe-nonce | 63b0c2bbb22de00b4c7e64b3798585811ebdc440e9e7d7351eb3b59c8da09029 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRTg4OjNEMTE1MDozRTBCQjk6NTFEREZEOjZBNUIyNkI4IiwidmlzaXRvcl9pZCI6IjczODcxNjcyODY3NTczOTMyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d24c4454728a6aed142e6d57ff4f0381efeeedb6f157a3d56f04a15408d33f6e |
| hovercard-subject-tag | issue:4581101551 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/27558/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4e8c27a76966ec139b015d4aeb8f92a45f3176364f2099dccbcece7728533706/PowerShell/PowerShell/issues/27558 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4e8c27a76966ec139b015d4aeb8f92a45f3176364f2099dccbcece7728533706/PowerShell/PowerShell/issues/27558 |
| og:image:alt | Summary The array-subexpression operator itself throws System.ArgumentException: Argument types do not match when it wraps a System.Collections.Generic.List[object] created by New-Object. UI Automa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | shuangxue520 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width